-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_fixed.py
More file actions
30 lines (25 loc) · 1.09 KB
/
Copy pathtrain_fixed.py
File metadata and controls
30 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
mlflow.set_tracking_uri("http://localhost:5000")
os.environ["MLFLOW_S3_ENDPOINT_URL"] = "http://minio-service.ml-model.svc.cluster.local:9000"
os.environ["AWS_ACCESS_KEY_ID"] = "admin"
os.environ["AWS_SECRET_ACCESS_KEY"] = "admin123"
mlflow.set_experiment("fraud-detection-experiment")
X, y = make_classification(n_samples=1000, n_features=6, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
with mlflow.start_run() as run:
accuracy = model.score(X_test, y_test)
mlflow.log_metric("accuracy", accuracy)
mlflow.log_param("model_type", "RandomForestClassifier")
mlflow.sklearn.log_model(
sk_model=model,
artifact_path="model",
registered_model_name="fraud-model"
)
print(f"Success! Run ID: {run.info.run_id}")