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.
A perfectly calibrated model has this hold for every : 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
- : the number of bins the predictions are sorted into.
- : how many predictions fell in bin .
- : the fraction of them that were positive.
- : 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.
The Brier score avoids binning by scoring every prediction directly, but it mixes calibration and ranking into one number.
The two standard repairs
Platt scaling fits a one-dimensional logistic regression to the model's scores, learning just and on a held-out set.
Temperature scaling is the same idea with a single parameter: divide the logits by 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
- Train the model on the training set as usual.
- Score a held-out set the model has never seen.
- Fit the calibrator on those scores against the true labels.
- At prediction time, pass every raw score through the fitted calibrator.
- 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.