Topic 5 of 6 · 5 min read
Comparing models with baselines and intervals
Goal: Decide whether one model really beats another using a baseline, a bootstrap interval and per-segment scores.
Two models differ by one or two points on a test set only when that gap is bigger than the noise in the test set, and only when both beat a trivial baseline on the cases that matter. A single score on a single split cannot show that.
Check yourself · 1 of 3
Why compute a baseline score before evaluating a model?
Why it matters
A 0.5-point gain on 400 test rows can vanish if you resample. Teams ship the "better" model, see no gain in production, and cannot say why. Averages also hide failures: a model can improve overall and get worse for a customer segment you are accountable to.
A checklist
- Start with a baseline. Predict the majority class, the mean, or last period's value. In scikit-learn,
DummyClassifierandDummyRegressordo this. If the model barely beats it, the problem is not the model's cleverness. - Use the same split and metric for both models. Compare on identical rows, chosen before looking at results.
- Put an interval on the difference. Resample the test set with replacement many times, score both models on each resample, and look at the spread of the difference.
- Break scores down by segment. Region, device, language, new versus returning customers, the rare class. Report the worst segment, not just the mean.
- Keep the test set for the end. Tune on validation data or with cross-validation; touch the test set once.
import numpy as np
rng = np.random.default_rng(0)
n = len(y)
diffs = []
for _ in range(1000):
i = rng.integers(0, n, n)
diffs.append(score(y[i], pa[i]) - score(y[i], pb[i]))
lo, hi = np.percentile(diffs, [2.5, 97.5])
If the interval for A - B contains 0, you do not have evidence that A is better.
Before and after
Before: "New model F1 0.81, old 0.79, shipping." After: baseline F1 0.62. Bootstrap interval for the gain is -0.01 to +0.05, so it includes zero. By segment, the new model is 4 points better on desktop and 6 worse on mobile. Decision: keep the old model, collect more mobile data.
What goes wrong
- Peeking. Trying 30 variants against one test set and reporting the best inflates the winner.
- Comparing different data. Scores on a refreshed test set are not comparable with last quarter's.
- Resampling rows that are not independent. If one user has many rows, resample users, not rows.
- Ignoring cost. A tiny gain from a model ten times slower may not be worth shipping.
Examples
Gain inside the noise
Model B scores 0.842 accuracy and Model A 0.835 on 600 test rows. Bootstrapping the difference gives a 95% interval of -0.012 to +0.026. Zero is inside it, so the data does not show that B is better. More test data, or a different test of cost and speed, should decide.
Better on average, worse for someone
A support-ticket classifier improves overall recall from 0.74 to 0.77. By language, English improves from 0.76 to 0.80 and Spanish falls from 0.70 to 0.62. The average improved because most tickets are English. If Spanish customers are a commitment, the new model fails the check.
Key points
- Always score a trivial baseline first; a model is only as good as its margin over it.
- Compare models on identical rows with a metric and split chosen before seeing results.
- A bootstrap interval on the score difference shows whether the gain is larger than test-set noise.
- Per-segment scores reveal regressions that an overall average hides.
- Resample at the level of independent units, such as users, not individual rows.
Common mistakes
- Declaring a winner from a one-point gap on a single split with no interval.
- Skipping the baseline, so a weak model looks impressive.
- Reusing one test set for dozens of model variants and reporting the best score.
- Resampling rows when many rows come from the same user or session.
Check yourself · 2 of 3
Bootstrapping the test set gives a 95% interval of -0.01 to +0.04 for the gain of the new model over the old one. What do you conclude?
Check yourself · 3 of 3
A new model improves the overall score but you have not looked at subgroups. What is the risk?
Practice items, not counted towards your mastery.
Start here
- Google ML Crash Course: classification (opens in a new tab)CourseFree
Accuracy, precision, recall and ROC/AUC explained with worked confusion-matrix numbers.
- scikit-learn: metrics and scoring (opens in a new tab)DocsFree
The reference for every metric named in this skill, with the exact function and its edge cases.
- scikit-learn: probability calibration (opens in a new tab)DocsFree
Reliability curves, Brier score and the sigmoid and isotonic recalibration methods, with plots.
More for this topic
- scikit-learn: DummyClassifier (opens in a new tab)DocsFree
The baseline model that predicts the majority class or priors, the floor any real model must beat.
- Cross-validation: evaluating estimator performance (scikit-learn) (opens in a new tab)DocsFree
How repeated splits give a spread of scores instead of one number, and the pitfalls of leakage.