How to use MLflow to Track and Structure Machine Learning Projects?

What is Experiment Tracking, and Why is it important?

What is MLflow?

Graphic shows Key Components of MLflow (Source: medium.com/pytorch)

MLflow Tracking

MLflow.start_run() -- starts/executes a run.
MLflow.end_run() -- ends a currently active run.
MLflow.log_artifacts() -- logs all the files given in a directory as artifacts.
....

MLflow Projects

The image represents how MLflow Projects works: Image Source: infoq.com

MLflow Models

Model Registry

Benefits Of Using MLflow

Tracking ML Experiments using MLflow

UI Workflow

pip install MLflow
import MLflow
import MLflow.sklearn
MLflow.set_experiment(experiment_name="MLflow demo")
MLflow.log_metric("accuracy", model_accuracy) //metric logging
MLflow.log_metric("precision", precision) //metric logging
MLflow.sklearn.log_model(model, "model") //model loggingMLflow.log_param("max_depth", max_depth) //hyperparameters logging
...
MLflow ui
The image shows MLflow UI

API Workflow

from MLflowf.tracking import MLflowClient
client = MLflowClient()
experiments = client.list_experiments() # returns a list of MLflow.entities.Experiment
run = client.create_run(experiments[0].experiment_id) # returns MLflow.entities.Run
client.log_param(run.info.run_id, "hello", "world")
client.set_terminated(run.info.run_id)

Some Highlights of MLflow

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store