Skip to content

A short tutorial on how to use MLflow on Python

Notifications You must be signed in to change notification settings

Jeremie-Ch/mlflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mlflow

A quick demo on how to use MLFlow.
The main.py file is an example of MLFlow run.
Link to the doc: https://www.mlflow.org/docs/latest/tracking.html

Introduction

MLflow is a tool that allows you to manage machine learning models lifecycle. It is used to track runs, save parameters, metrics and models in order to compare them. Moreover, it is possible to package your model and to serve it onto a server.

Useful commands and functions

  • mlflow.set_tracking_uri(http://10.3.15.100:8080) connects the run to the right server. If not specified, default port is localhost:5000.

  • Use mlflow.start_run() to start a run and write your code underneath. The function can take optional parameters if needed, such as experiment_id [str] , run_name [str] or description [str]. More details here.

  • Log parameters using mlflow.log_params(name, parameter). More details here.

  • Log metrics using mlflow.log_metric(name, metric). More details here.

  • Log artifacts using mlflow.log_artifact(path_to_file, artifact_path). artifact_path is the path to the folder that will contain the artifact. More details here. Artifacts can be viewed by clicking on the run's name on MLFlow server. They also can be retrieved directly from Minio where they are stored.

  • Log models using log_model(model, artifact_path) function. The function depends on the model you are using. For example, if your model is from scikit-learn, you would use mlflow.sklearn.log_model(), if it is from keras, then use mlflow.keras.log_model() and so on. The model will then be saved as an artifact. You can find details on mlflow.sklearn.log_model() here.

MLFlow UI

After running your python script, logs are saved on the server and you can view them on http://10.3.15.100:8080.

On the main page, you'll find the list of runs for each experiment along with their metrics and parameters. The experiment selected here is named Default.

mlflow ui

  • If you click on the run's name, you'll access to its details, including artifacts.

    details1 details2

  • You can also plot metrics by clicking on it.

    click_on_metric plot_chart

Create an experiment

MLflow is organized in experiments. One experiment can contain as many runs as needed but one run is associated with only one experiment.

You can create a new experiment from your python code, by using mlflow.create_experiment(name). But for more convenience, a python script has been made for this purpose. From the terminal, go to the folder containing create-experiment.py and enter the command python create-experiment [name].

Here I entered python create-experiment my-new-experiment. It is immediately visible from the UI.

ui_new_exp

Experiments can also be created from MLFLow UI by clicking on the top-left + button.

About

A short tutorial on how to use MLflow on Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published