Skip to main content

MLflow Tutorial for Machine Learning in Python

Track every machine learning experiment you run in Python with MLflow: parameters, metrics, charts and models, compared side by side in the MLflow UI. Beginner-friendly parts take you from installing MLflow and running your own tracking server to evaluating, registering and serving scikit-learn models, all on your own computer.

10 parts · 6 h 16 min read

Start with Part 1

Get the Source Code​

Every part of this series is free to read. Each finished, tested project lets you skip ahead or check your work.

  1. Install MLflow and Track Your First Experiment

    · 42 min read

    Install MLflow 3.18 with uv, start your own tracking server on your computer, and log your first machine learning experiment from Python: parameters, metrics, tags and a chart for a scikit-learn house price model, then compare the runs in the MLflow UI.

  2. Log Metrics Over Time and System Metrics

    · 39 min read

    Log a validation score at every training step with MLflow's step argument, compare the learning curves of three random forests in the MLflow UI, read a curve back in Python with get_metric_history, and record the computer's CPU, memory, disk and network use with system metrics. Real output from MLflow 3.18.0.

  3. Log Artifacts and Datasets

    · 30 min read

    Record the data every MLflow run trained, validated and tested on with mlflow.data and log_input, and save the run's files with it: a feature importance table with log_table, the model's full settings with log_dict and a CSV of every test prediction with log_artifact. Then compare datasets and files across runs in the MLflow UI. Real output from MLflow 3.18.0.

  4. Search and Filter Runs

    · 27 min read

    Search an MLflow experiment's runs by metric, parameter, status and dataset in the UI, rank the finished runs from Python with mlflow.search_runs in a leaderboard command, find a run by name on the server, and delete a run that failed. Real screens and output from MLflow 3.18.0.

  5. Autologging and Hyperparameter Tuning with Nested Runs

    · 38 min read

    Start a second project, a term deposit classifier, let MLflow's scikit-learn autologging record its training, and run a GridSearchCV search that MLflow logs as one parent run with a child run per candidate. Read, compare and rank them in the UI. Real screens and output from MLflow 3.18.0.

  6. Log, Load and Validate Models

    · 44 min read

    Start a third project, a model that predicts which online shoppers will buy, and log it to MLflow with a signature, an input example, its test score and the safe skops format. Find it in the UI, load it by its ID to score new sessions, check files against its signature, and test it in a fresh environment. Real screens and output from MLflow 3.18.0.

  7. Evaluate Models and Set Quality Gates

    · 42 min read

    Evaluate Part 6's shopper model with mlflow.models.evaluate: metrics and plots on a run, linked to the model and a named test dataset. Add balanced accuracy as a custom metric, then a quality gate a new model must pass, minimum scores plus beating the model in use, with an exit code a pipeline can act on. Real screens and output from MLflow 3.18.0.

  8. Register, Version and Promote Models with the Model Registry

    · 46 min read

    Register Part 7's shopper models in the MLflow Model Registry: version 1 from the UI with a champion alias and a description, then a promote command that registers each candidate as a new version, runs the quality gate against the champion and moves the alias only when the candidate wins. Roll back by moving the alias. Real screens and output from MLflow 3.18.0.

  9. Serve a Model as a REST API and in Docker

    · 34 min read

    Serve Part 8's champion shopper model as a REST API with mlflow models serve, ask it for predictions in JSON and CSV, read how it refuses bad requests, and write a call-api command that any program could be. Then package the champion in a Docker image with mlflow models build-docker and serve the same predictions from a container. Real output from MLflow 3.18.0 and Docker Desktop 4.100.1.

  10. Production Checklist and Recap

    · 34 min read

    Make the series' MLflow setup ready for real use: record the Git commit on every run, check the tracking server's network protection, back the server up while it runs, restore the backup on a second server, and upgrade the database the documented way. Then a production checklist and a recap of all ten parts. Real output from MLflow 3.18.0.