Sub topic 1
Why Experiments Need Tracking
Prerequisites
This chapter assumes that you can write basic Python, train a model with scikit-learn or a similar library, use a terminal and pip, and understand train/test splits and metrics such as accuracy. You should also be comfortable reading a small machine-learning script and identifying its inputs, settings, and outputs.
The reproducibility problem
A machine-learning experiment is more than the model class. Its result depends on many choices:
- Which data was used and how it was cleaned.
- Which features were included.
- How the data was split into training and test sets.
- Which algorithm and hyperparameters were selected.
- Which software and library versions were installed.
- Which random seed was used.
- Which metric was measured, and on which data.
If you record only “the model reached 92% accuracy,” another person cannot reliably reproduce that result. Even you may have trouble reproducing it a week later. You might remember the model but forget that you removed missing rows, changed the test size, or used a different value of C.
Tracking turns these hidden decisions into recorded evidence. The goal is not to save every possible detail. The goal is to save enough information to answer three questions:
- What did we try?
- What happened?
- Can we run it again or build on it?
What MLflow records
MLflow Tracking organizes work into experiments and runs. An experiment is a named collection of related work, such as iris-baseline or fraud-model-search. A run is one execution of training or evaluation within that experiment.
During a run, MLflow can record several kinds of information:
| Information | Example | Why it matters |
|---|---|---|
| Parameter | `C = 1.0` | Describes a setting chosen before training |
| Metric | `test_accuracy = 0.93` | Records a measured result |
| Tag | `stage = baseline` | Adds searchable context |
| Artifact | `confusion-matrix.png` | Preserves a file produced by the run |
Parameters are usually configuration values. Examples include the learning rate, number of trees, batch size, or test-set fraction. Metrics are numerical observations, such as accuracy, loss, precision, or validation error. Tags are labels that help people classify and search for runs. Artifacts are files, such as plots, transformed data samples, configuration files, logs, or saved models.
MLflow does not automatically know what your experiment means. You must decide which values are important and log them consistently. A tracking system preserves the information you provide; it cannot recover a preprocessing choice that your code never recorded.
Why a single metric is not enough
Suppose two runs both report an accuracy of 0.93. They may still have very different value.
One model may use a smaller, cleaner data set. Another may use the full data set but perform poorly on one class. One may be fast and easy to deploy, while the other may require expensive feature computation. Comparing a single metric hides these differences.
Tracking lets you compare the result with the conditions that produced it. You can ask:
- Did the higher accuracy come from a meaningful parameter change?
- Was the test set the same for every run?
- Did training loss improve while validation loss worsened?
- Which run produced the artifact or model now under review?
- Can the team explain why one run became the baseline?
A useful run record connects settings, observations, and outputs. That connection is the main benefit of experiment tracking.
From notes to an experiment history
Manual notes in a document or spreadsheet can work for a few trials, but they become fragile as experiments multiply. People may use different parameter names, overwrite values, omit failed runs, or copy results incorrectly. Files can also become detached from the code and model they describe.
MLflow gives each run an identity and stores its information together. A run can remain useful even when it fails. Recording a failed run helps explain what was attempted and prevents the team from repeating the same mistake. You can later filter runs by tags, sort by metrics, inspect parameters, and retrieve artifacts.
The important change is behavioral: training becomes an auditable sequence of experiments rather than a collection of undocumented commands.
What tracking cannot guarantee
Tracking improves reproducibility, but it does not guarantee it. If the input data changes and you record only its filename, the same filename may refer to different content later. If a preprocessing step happens outside the tracked code, the run record may be incomplete. If random seeds are not controlled, repeated runs may differ. If the environment is not captured, library changes may alter behavior.
Treat tracking as part of a wider reproducibility practice. Version the code, identify the data, control randomness where practical, record the environment, and make the evaluation procedure explicit. MLflow helps connect these pieces to each run.
Exercise
Two runs have the same test accuracy, but one used a different test split. Why should you avoid treating them as equivalent?
Show answer
The metric was measured on different data, so the values are not directly comparable. The split and other evaluation conditions must be recorded and aligned before choosing a better run.