Start studying
Module 1 · Machine Learning Module contents
Module 1  ·  Card 49 / 55intermediate

Calibration

A calibrated model's probabilities mean what they say.

If it says seventy percent a hundred times, about seventy of those should come true.

Ranking well and being calibrated are different things, and a model can do one without the other.

Boosted trees and neural networks are often overconfident and need correcting.

Platt scaling and isotonic regression fit that correction on held-out data.

Learn in depth ↓
Module 01 · Machine Learning · 55 concepts
In depth  /  15 lines

Calibration, in more detail

A calibrated model is one whose probabilities can be taken at face value.

Of all the times it says seventy per cent, about seventy per cent should happen.

That is a different question from whether it ranks cases correctly.

A model can order every case perfectly and still state absurd probabilities.

Ranking is what AUC measures, and calibration is what AUC ignores entirely.

It matters whenever the number itself is used rather than the order.

Expected cost, pricing, triage thresholds and any human decision all use the number.

A reliability diagram is the standard check, plotting predicted against observed rates.

A perfectly calibrated model traces the diagonal.

Boosted trees usually sit above it, being systematically overconfident.

Neural networks with modern training are often overconfident too.

Logistic regression tends to be well calibrated already, by construction.

Platt scaling fits a small logistic curve to correct the outputs.

Isotonic regression is more flexible and needs more data to avoid overfitting the correction.

Fit either on held-out data, never on the data the model was trained on.

Want the full technical article? Wikipedia ↗
Deep dive

What is underneath Calibration

Two different questions about a model

Ranking asks whether the model puts the right examples above the wrong ones. Calibration asks whether the number it prints is a probability.

P(y=1∣p^=p)=pP\big(y = 1 \mid \hat{p} = p\big) = p

A perfectly calibrated model has this hold for every pp: of all the cases it scored 0.7, exactly 70 percent are positive.

A model can rank perfectly and be badly calibrated, and a model can be perfectly calibrated and rank no better than chance.

Which one you need depends on what happens next. A threshold only needs the ranking. A cost calculation, a triage queue or anything multiplied by a number needs the probability.

Measuring it

ECE=∑b=1Bnbn∣acc(b)−conf(b)∣\mathrm{ECE} = \sum_{b=1}^{B} \frac{n_b}{n} \left| \mathrm{acc}(b) - \mathrm{conf}(b) \right|
  • BB: the number of bins the predictions are sorted into.
  • nbn_b: how many predictions fell in bin bb.
  • acc(b)\mathrm{acc}(b): the fraction of them that were positive.
  • conf(b)\mathrm{conf}(b): the average score in that bin.

Expected calibration error bins the predictions, compares each bin's average score with its actual rate, and averages the gaps by bin size.

It depends on the binning, so the bin count has to be reported with the number for it to mean anything.

BS=1n∑i=1n(p^i−yi)2\mathrm{BS} = \frac{1}{n}\sum_{i=1}^{n} (\hat{p}_i - y_i)^2

The Brier score avoids binning by scoring every prediction directly, but it mixes calibration and ranking into one number.

The two standard repairs

p^=11+exp⁡(Af(x)+B)\hat{p} = \frac{1}{1 + \exp(A f(\mathbf{x}) + B)}

Platt scaling fits a one-dimensional logistic regression to the model's scores, learning just AA and BB on a held-out set.

p^=11+exp⁡(−z/T)\hat{p} = \frac{1}{1 + \exp(-z / T)}

Temperature scaling is the same idea with a single parameter: divide the logits by TT before the sigmoid or softmax.

One parameter cannot reorder anything, so accuracy and AUC are mathematically unchanged and only the spread of the probabilities moves.

Isotonic regression fits any non-decreasing function instead, which is more flexible and needs far more held-out data before it stops overfitting.

One calibration, in order

  1. Train the model on the training set as usual.
  2. Score a held-out set the model has never seen.
  3. Fit the calibrator on those scores against the true labels.
  4. At prediction time, pass every raw score through the fitted calibrator.
  5. Re-measure ECE on a third split, because a calibrator can overfit like anything else.

Why it is fitted on held-out data, always

Fitted on the training scores, the calibrator learns the model's overconfidence on examples it memorised, which is not the overconfidence it shows in production.

Modern neural networks are systematically overconfident, and the cause is the training objective rather than a bug.

Cross-entropy keeps rewarding a higher probability on an example that is already correct, long after the example is settled.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
A model ranks cases perfectly but says 95 percent when the true rate is 60 percent. What is wrong?
Machine Learning

55 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close