Skip to content

MLflow Experiment Tracking: What to Log and Why

A list of training runs with the best run highlighted and promoted to a saved model.

A week after you trained the good model, nobody remembers which settings produced it. Experiment tracking fixes that by recording every training run: what you changed, how it scored, and what it produced. MLflow is a widely used open-source tool for doing it.

The problem it solves

Machine learning is a long series of small experiments: a different feature set, another hyperparameter, a new data split. Without a record, results live in notebook cells, file names like model_final_v3_really_final.pkl and memory. You cannot reproduce the best run, compare runs fairly, or explain to a colleague why a model was chosen.

What MLflow Tracking records

MLflow groups work into experiments, and each training attempt is a run. A run can store parameters, which are the settings you chose, metrics, which are the scores you measured, and artifacts, which are files such as plots, a saved model or the dataset version used. A web interface lets you sort and compare runs side by side.

A minimal example

import mlflow

mlflow.set_experiment("churn-model")

with mlflow.start_run():
    mlflow.log_param("max_depth", 6)
    model = train(max_depth=6)
    auc = evaluate(model)
    mlflow.log_metric("roc_auc", auc)
    mlflow.log_artifact("feature_importance.png")

Here train and evaluate stand for your own functions. For common libraries such as scikit-learn, MLflow also offers autologging, which records parameters and metrics for you with a single call, though you should still check what it captured.

What is worth logging

  • The hyperparameters and feature list used for the run.
  • The data version or a fingerprint of the training data, so a score can be tied to its inputs.
  • The random seed, which matters for reproducibility, as covered in random seed reproducibility.
  • Metrics on a held-out set, and the exact split used.
  • Useful files: the trained model, evaluation plots and any explanation output, such as that discussed in what SHAP values tell you.
  • The code version, such as the Git commit.

Comparing runs honestly

Tracking only helps if comparisons are fair. Runs should use the same data split and the same metric, otherwise a higher number may just reflect an easier test set. When you search many settings, record all the runs, not only the winner, so you can see how much a result depends on luck. The search methods themselves are compared in hyperparameter tuning methods.

From tracking to a model registry

Once a run produces a model you want to keep, MLflow’s model registry lets you give it a name and version and mark which version is in use, so the model that serves predictions can be traced back to the run that created it. That traceability matters once a model is deployed and needs monitoring, as in model drift, and when features are shared across models, as in feature stores.

See it in a project

My Telecom Churn Prediction project tracks its experiments, covering features, hyperparameters and splits, so results can be compared and reproduced.

A quick checklist

  1. Does every training run log its parameters, metrics and artifacts?
  2. Can you tie each score to a data version and a code version?
  3. Do compared runs share the same split and metric?
  4. Did you keep the failed and middling runs, not just the best?
  5. Can you trace a deployed model back to the run that created it?

If you want experiment tracking and deployment set up around your models, see my machine learning and MLOps service.

FAQ

What is MLflow used for?
It is an open-source platform for managing the machine learning lifecycle. Its tracking component records parameters, metrics and files for each training run, so experiments can be compared and reproduced.

What is the difference between an experiment and a run in MLflow?
A run is one training attempt. An experiment is a group of related runs, such as every attempt at building one model.

Do I need MLflow for a small project?
Not necessarily. For a handful of runs, a simple spreadsheet or log file may be enough. Tracking tools pay off once you run many experiments or work in a team.

Related posts

Leave a comment

Your email address will not be published. Required fields are marked *