Sub topic 1
Why Track Machine-Learning Experiments
Prerequisites
Assume you know basic Python, including context managers and f-strings. You should also understand train/test splits and evaluation metrics, and have access to a Databricks notebook attached to compute.
Why Track Experiments
Training a model usually involves many choices: the data split, feature transformations, algorithm, and hyperparameters. If you record only the final model score, you cannot reliably explain how you got there or reproduce it later.
MLflow Tracking stores these details for each training attempt. This creates an evidence trail that helps you compare models, find the configuration that produced a result, and diagnose changes between runs.
Experiments and Runs: The Core Model
An experiment is a named container for related training work. A run is one execution inside an experiment. For example, an experiment might contain every version of an iris classifier, while each run uses a different value for C.
A run can contain several kinds of information:
| Information | Meaning | Example |
|---|---|---|
| Parameter | An input chosen before training | `C = 1.0` |
| Metric | A measured result | `accuracy = 0.93` |
| Tag | A label or note | `stage = exploration` |
| Artifact | A saved file or model | `model/` |
The basic workflow is to select an experiment, start a run, and log information while the code executes.
import mlflow
mlflow.set_experiment("/Users/<your-email>/iris-tracking")
with mlflow.start_run(run_name="baseline") as run:
mlflow.log_param("C", 1.0)
mlflow.log_metric("accuracy", 0.93)
mlflow.set_tag("stage", "exploration")
print(run.info.run_id)Where Runs Go on Databricks
Databricks supports two common experiment locations:
- A notebook experiment is associated with a specific notebook. It is convenient when one notebook owns the complete investigation.
- A workspace experiment is a separate experiment object at a workspace path. It is better when several notebooks, jobs, or team members need to write to the same experiment.
Set the experiment explicitly when moving from exploration to shared work. An explicit path prevents runs from being split across unintended experiments.
Logging Parameters, Metrics, and Tags
Log parameters before or during training, metrics after evaluation, and tags for searchable context such as owner, purpose, or dataset version. Use stable names so runs can be compared consistently.
Exercise
You train three models with different learning rates. Should they use three experiments or three runs?
Show answer
Use three runs in one experiment because they are related trials of the same investigation.