Sub topic 8
Comparing runs in the experiment UI
This chapter assumes you can create runs and log parameters and metrics with mlflow.start_run, log_param and log_metric. It also assumes your runs land in a Databricks experiment. You will use the experiment page to see which run performed best and why.
Prepare runs worth comparing
Comparison only works when runs log the same names. If one run logs accuracy and another logs test_accuracy, the UI treats them as different metrics and you cannot chart them together. Pick the names once and reuse them.
The following code creates four runs that differ only in the regularization strength C.
import mlflow
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
mlflow.set_experiment("/Users/<your-email>/iris-tracking")
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
for c in [0.01, 0.1, 1.0, 10.0]:
with mlflow.start_run(run_name=f"C={c}"):
model = LogisticRegression(C=c, max_iter=200).fit(X_train, y_train)
mlflow.log_param("C", c)
mlflow.log_metric("test_accuracy", model.score(X_test, y_test))
mlflow.set_tag("stage", "exploration")Open the experiment page
Open the experiment from the Experiments page in the workspace sidebar. For a notebook experiment, use the experiment icon in the notebook's right sidebar. The runs table lists each run with its name, creation time, and the parameters, metrics and tags you logged. The exact layout changes between Databricks releases, so look for the same features under slightly different labels.
Useful table controls:
- Columns: show or hide parameter, metric and tag columns.
- Sort: click a metric column header to rank runs by it.
- Filter: search with the same syntax as
search_runs, for examplemetrics.test_accuracy > 0.9.
Compare selected runs
Tick the checkboxes next to two or more runs and choose Compare. The comparison view offers several visualizations.
| View | Best for |
|---|---|
| Parallel coordinates | Seeing how several parameters relate to a metric at once |
| Scatter plot | Plotting one parameter or metric against another |
| Contour plot | Looking at two parameters against one metric |
| Run table | Reading exact values side by side |
For the four runs above, a scatter plot of C against test_accuracy shows whether more regularization helps or hurts. Differences in a single parameter are easy to read. When many parameters vary at once, parallel coordinates is the better choice.
Inspect a single run
Click a run name to open its detail page. It shows the logged parameters, metrics, tags and artifacts. Its Metrics tab charts values logged with a step. Use the detail page to confirm that a promising run is trustworthy before you act on it. Check the artifacts, such as a logged model, and the tags that say what the run was for.
Common errors
- Metrics missing from the table. Metrics are logged per run. If a run failed before logging them, its cells are empty. Check that the run status is finished.
- Misleading comparisons. Runs trained on different data splits are not comparable. Log a tag or parameter such as
random_stateso you can see the difference. - Too many runs. Name runs clearly and use tags like
stageto filter. Otherwise the table becomes hard to scan. - Only the final metric charted. If you log a metric once, you get a single point. Log with
step=inside a training loop to get a curve.
Exercise
You compare two runs in the UI. One logged accuracy and the other logged test_accuracy. Why can't you chart the two together, and how do you fix it?
Show answer
The UI matches metrics by exact name, so accuracy and test_accuracy count as different metrics. Rerun or relog with one agreed name, such as test_accuracy, in both runs.