Foundations to Frontier
Tests
D. Classical Machine Learning › D0 Core Concepts (concept pages)

Calibration, Reliability Diagrams and Platt Scaling

A classifier is calibrated if its probabilities mean what they say: among all cases given 70%, about 70% are positive. Many models are not. Boosted trees and SVMs push scores to the extremes or squash them, naive Bayes is overconfident, and modern neural networks are often overconfident. Calibration matters whenever probabilities feed a decision, a cost calculation or another model. This page covers reliability diagrams, the expected calibration error, the Brier score decomposition, and recalibration methods: Platt scaling, temperature scaling, isotonic regression and histogram binning, plus adjusting for a change in class prior. In the exercises you implement the diagnostics and the calibrators; then you test which calibrator fixes which kind of miscalibration and how much calibration data each needs.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

When “70% chance” really means 70%

A weather forecaster who says “70% chance of rain” is trustworthy if it actually rains on about 70% of the days they say that. If it only rains on 40% of those days, the forecaster is overconfident, and you’d be wise to mentally turn their numbers down. Calibration is checking and fixing exactly this for a model.

Reliability diagram and recalibration
predicted probabilityobserved frequency
expected calibration error: 0.114 (a = 1, b = 0 is perfectly calibrated)
Below the diagonal = overconfident (says 90%, right 70% of the time). Platt scaling fits two numbers and fixes any distortion of the form a·logit + b with little data; isotonic regression fits any monotone curve but needs more examples and is jumpy when n is small. Dot size shows how many test cases fall in each bin.
Why engineers care

Risk calculations multiply probabilities by consequences. A collision probability that is ten times too low, or a failure probability inflated by an overconfident model, leads to wrong safety decisions even when the model ranks cases perfectly.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A model says 90% for many cases but only 60% are positive. It is…
  2. 2. A calibrated model's 30% predictions are positive about…
  3. 3. Calibration matters most when…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Diagnosing calibration

  • Reliability diagram: bin predictions (for example 10 bins), plot mean predicted probability against observed frequency. A calibrated model lies on the diagonal; below it means overconfident in that range.
  • ECE: the count-weighted average gap |confidence − frequency| over bins. MCE is the largest gap.
  • Brier score = mean (p − y)², decomposed as reliability − resolution + uncertainty. Reliability is the calibration error; resolution is how much predictions vary with the truth.
  • Log-loss also rewards calibration.

Typical behaviour

Model Usual miscalibration
logistic regression well calibrated (it optimises log-loss)
naive Bayes overconfident (independence assumption)
SVM, boosted trees scores not probabilities; sigmoid-shaped distortion
random forest pulled away from 0 and 1 (averaging)
deep networks often overconfident
from sklearn.calibration import CalibratedClassifierCV, calibration_curve
cal = CalibratedClassifierCV(model, method="sigmoid", cv=5).fit(X, y)      # Platt; method="isotonic" for PAV
frac_pos, mean_pred = calibration_curve(y_test, cal.predict_proba(X_test)[:, 1], n_bins=10)
📝 Quick check (Level 1)
0/3 answered
  1. 1. A reliability curve below the diagonal at high probabilities means…
  2. 2. Which model is usually well calibrated out of the box?
  3. 3. ECE averages the gaps weighted by…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Recalibration methods

All of them are fitted on a held-out calibration set, or by cross-validation, never on the training data.

  • Platt scaling: p = σ(a·s + b), fitted by logistic regression on the scores. Two parameters fix any affine distortion of the logit (too sharp, too flat, shifted).
  • Temperature scaling: p = σ(s / T), one parameter. It fixes sharpness but not a shift. It is the standard for neural networks, where the multiclass version divides all logits by T.
  • Isotonic regression: the best non-decreasing step function, fitted with the pool-adjacent-violators (PAV) algorithm. It fixes any monotone distortion but needs more data and can overfit.
  • Histogram binning: replace each bin’s predictions by its observed frequency.
  • Prior shift: if training prevalence π differs from deployment prevalence π′, multiply the odds by (π′/π)·(1 − π)/(1 − π′).
🐍 Exercise 1: diagnosing and fixing calibration
Compute reliability-diagram bins, ECE and MCE; decompose the Brier score; fit Platt scaling by Newton's method with Platt's smoothed targets; implement isotonic regression with pool-adjacent-violators and apply it to new scores; check them on calibrated and overconfident predictions.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Temperature scaling cannot fix…
  2. 2. Isotonic regression assumes the calibration map is…
  3. 3. Calibrators must be fitted on…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Calibration in practice

  • Small calibration sets (hundreds of examples): prefer Platt or temperature scaling. Large sets: isotonic regression or binning can fix any shape.
  • Calibration does not change ranking for monotone methods, so ROC-AUC is unchanged. Isotonic regression can create ties.
  • Multiclass: temperature scaling, or one-vs-rest Platt or isotonic followed by renormalisation. Use classwise ECE as well as confidence ECE.
  • ECE is a noisy, binning-dependent estimate. Report the number of bins, use enough test data, and look at the diagram.
  • Recalibrate after distribution shift, and for each deployment site if prevalence differs.

Interview questions.

  • Why are boosted trees poorly calibrated? Boosting pushes margins toward ±∞ on training data, and its scores are not optimised as probabilities.
  • Can a model have AUC 0.99 and terrible calibration? Yes. Ranking and calibration are separate properties.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Does Platt scaling change ROC-AUC?
  2. 2. With 200 calibration examples, prefer…
  3. 3. A model trained with 50% positives is deployed where 5% are positive. Fix?

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which calibrator for which problem?

Exercise 1.

  • True probabilities give ECE 0.007, which is sampling noise.
  • An overconfident map gives ECE 0.089.
  • On scores three times too sharp, Platt scaling recovers a = 0.343, close to the true 1/3.
  • The Brier score 0.1655 splits into reliability 0.0001 − resolution 0.0836 + uncertainty 0.25.

Exercise 2: four distortions, five calibrators, three calibration-set sizes. Values are test ECE on 10 000 examples, averaged over 15 repetitions. The ECE floor from finite test data is about 0.012.

Distortion n Uncalibrated Temperature Platt Isotonic 10-bin histogram
overconfident (3 × logit) 100 0.142 0.036 0.057 0.078 0.069
1 000 0.139 0.013 0.016 0.025 0.021
underconfident (0.4 × logit) 1 000 0.129 0.013 0.016 0.025 0.021
shifted (logit + 2) 1 000 0.342 0.251 0.016 0.025 0.021
curved (l + l³/6) 1 000 0.043 0.040 0.040 0.025 0.021
10 000 0.043 0.041 0.042 0.016 0.014
  • Parametric calibrators win when their form matches the distortion. Temperature fixes sharpness; Platt also fixes shifts; they need only about 100–1 000 examples.
  • Temperature scaling cannot remove a shift. ECE stays at 0.25.
  • For a non-sigmoid distortion, Platt and temperature are stuck at 0.040 however much data they get. Isotonic regression and binning keep improving with data.
  • Isotonic regression and binning use only the order of the scores. Their results are identical for all four distortions, but with 100 examples their excess log-loss is 11× that of temperature scaling (overfitting).
🐍 Exercise 2 (research): matching calibrators to miscalibration
Generate scores that are overconfident, underconfident, shifted and non-sigmoidally curved versions of the true logit; calibrate them with temperature scaling, Platt scaling, isotonic regression and histogram binning on 100, 1 000 and 10 000 examples; compare test ECE and excess log-loss over the true probabilities.

Calibration in AI, robotics and aerospace

  • Probabilistic risk assessment: failure-probability models must be calibrated before being multiplied by consequence costs.
  • Perception confidence: detector confidences feed tracking filters and planners; overconfident detections cause brittle behaviour.
  • Weather and space-weather forecasting: reliability diagrams are the standard verification tool.
  • LLMs and deep classifiers: temperature scaling and selective prediction (abstain when uncertain).

References

  1. J. Platt (1999). “Probabilistic outputs for support vector machines and comparisons to regularized likelihood methods.” Advances in Large Margin Classifiers.
  2. B. Zadrozny, C. Elkan (2002). “Transforming classifier scores into accurate multiclass probability estimates.” KDD.
  3. A. Niculescu-Mizil, R. Caruana (2005). “Predicting good probabilities with supervised learning.” ICML.
  4. C. Guo, G. Pleiss, Y. Sun, K. Q. Weinberger (2017). “On calibration of modern neural networks.” ICML.
  5. A. H. Murphy (1973). “A new vector partition of the probability score.” Journal of Applied Meteorology 12(4).