Developing Machine Learning Models for Production
Sinan Ozdemir
Data Scientist and Author
An open-source platform for tracking and managing machine learning experiments. MLflow can be used to:
# standard scikit-learn imports
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# new imports from MLflow
import mlflow
import mlflow.sklearn
with mlflow.start_run(): # Start an MLflow run assuming we have data prepared
# Build and train model
rf = RandomForestClassifier()
rf.fit(X_train, y_train)
# Log parameters and model information
mlflow.log_param("n_estimators", rf.n_estimators)
mlflow.sklearn.log_model(rf, "model")
y_pred = rf.predict(X_test) # Evaluate model
accuracy = accuracy_score(y_test, y_pred)
mlflow.log_metric("accuracy", accuracy) # log the test accuracy metric
Developing Machine Learning Models for Production