Aller au contenu

Leçon 8 · Autologging and Comparison

Compare Runs and Choose a Winner

Compare MLflow runs in the UI and in code, set a selection rule before looking, handle trade-offs between metrics and check whether a difference is real.

Tracking pays off when you compare. The goal is not to find the run with the biggest number. It is to choose a model that will work well on new data and meet your limits.

Compare in the web interface

On an experiment page you can add columns for the parameters and metrics you care about, sort by a column, filter with the search syntax, and select several runs to compare them with charts. The layout of the interface changes between versions, so learn these ideas rather than exact button positions:

  • Table: scan many runs with chosen columns.
  • Line charts: see how metrics change over steps.
  • Parameter plots: see which settings tend to go with good scores.

Compare in code

For a repeatable decision, use code:

Python
import mlflow

runs = mlflow.search_runs(
    experiment_names=["churn-model"],
    filter_string="attributes.status = 'FINISHED' AND tags.data_version = '7'",
)
good = runs[runs["metrics.latency_ms"] <= 50]
winner = good.sort_values("metrics.val_f1", ascending=False).iloc[0]
print(winner["run_id"], winner["metrics.val_f1"])

Write the rule first

Decide before looking at results:

  1. The primary metric, such as validation F1.
  2. Guardrails, which are limits that the model must meet, such as latency below 50 ms.
  3. A tie-breaker, such as the simpler or cheaper model.

If you decide after seeing results, you can talk yourself into almost any winner.

Python Stand-in: pick a winner with a rule

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The highest score is rejected because the model is too slow. Among near-equal finalists, the smaller model wins.

Is the difference real?

A gap of 0.002 may be noise. Check how much your score moves when you change only the random seed or the validation split. Run several seeds, then compare the average and the spread.

Python Stand-in: score spread across seeds

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Here the gap is much smaller than the spread, so you cannot claim that one is better. Log each seed as its own run, with the seed as a parameter, and compare them together.

Protect the test set

Use the validation set to choose among runs. Then evaluate only the chosen model on the test set and log that result. If the test score is much worse than the validation score, treat it as a warning. Do not go back and tune on the test set.

Record the decision

When you pick a winner, add tags to the winning run, for example selected = true and selection_rule = best val_f1 with latency at most 50 ms, and write a short note. Weeks later, someone can see not only which model won, but why.

Comparing runs from different data versions, split methods or metric definitions is a common way to reach a false conclusion. Filter on those tags before comparing.

Trade-offs between metrics

Models rarely win on every measure. One may have higher recall and lower precision. Another may be a little weaker but much smaller. A useful technique is to find runs that are not dominated: no other run is at least as good on every measure and strictly better on one. This set is often called the Pareto front. From it, you pick based on your priorities.

For a churn example, a team might state: "We prefer recall, as long as precision stays above 0.6." That sentence is a rule you can apply in code, and it is easy to explain to people outside the team.

Slices before you decide

Before you declare a winner, compare candidates on important subgroups too. A model with the best average may be worse for new customers, who may matter most. Log slice metrics with clear names, such as val_recall_new_users, so you can add them as columns and filter on them. Small slices have noisy scores, so log the number of examples as well.

A note on charts

Charts are persuasive, which makes them risky. Watch for:

  • A vertical axis that does not start at zero, which makes tiny gaps look large.
  • Curves with different numbers of steps, which make runs look unfinished.
  • Comparing a smoothed curve with a raw one.
  • Many overlapping lines where the eye picks the loudest.

When a decision is important, check the numbers in a table as well.

Share the comparison

Other people should be able to see why you chose. Save a small table of the finalists with their metrics as an artifact on the winning run, or write it in the run note. Include the date and the person who decided. If a later model replaces this one, the next person can compare against the same table, not against a half-remembered conversation. This habit costs minutes and often saves days.

When no candidate qualifies

Sometimes every run breaks a guardrail or fails to beat the current model. That is a valid result. Keep the current model, write down what you learned, and decide what to try next. Lowering the bar just so that something can ship removes the protection that the rule was meant to give. If the rule itself was wrong, for example because the latency limit was unrealistic, change it openly, explain why, and apply the new rule to all candidates in the same way.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Why define the selection rule before viewing results?

    A rule set in advance protects you from after-the-fact justification.
  2. 2. Two models differ by 0.002 and scores vary by 0.006 across seeds. What do you conclude?

    A gap smaller than normal variation is weak evidence.
  3. 3. How should the test set be used when choosing among candidates?

    Selecting by test score turns the test set into another validation set.

Summary

  • Compare in the UI to explore, and in code to decide repeatably.
  • Set a primary metric, guardrails and a tie-breaker first.
  • Check variation across seeds before trusting small gaps.
  • Keep the test set for the final check and record why you chose.

Next: Nested Runs and Hyperparameter Tuning

Votre progression est enregistrée dans ce navigateur. Aucun compte nécessaire.