Interactive Explainer
Calibration & Reliability Diagrams
A model that says "0.97" should be right 97% of the time. Most aren't. The reliability diagram tells you exactly how off you are; ECE summarises it; temperature scaling collapses it — one scalar parameter, no retraining.
What 'calibrated' actually means
A classifier is calibrated if, among all examples where it predicts confidence $p$, the fraction that are actually correct is $p$. Across $p$. Always. Modern neural networks are notoriously over-confident: a softmax of 0.97 on a held-out test point is more likely to be right ~85% of the time than 97% (Guo et al., 2017).
The reliability diagram
Bin predictions by their confidence. For each bin, plot (mean predicted confidence) vs (empirical accuracy). On a calibrated classifier this lies on the diagonal. Above the diagonal: under-confident. Below: over-confident.
ECE (expected calibration error) is the weighted average of $|\text{bin acc} - \text{bin confidence}|$. MCE (max calibration error) is the worst bin. Brier and NLL are scoring rules that combine calibration and refinement.
Train a classifier and watch it miscalibrate
A 3-class RBF logistic regression on a 2-D dataset; we train past the calibration sweet spot to deliberately push it into the over-confident regime modern deep nets tend to inhabit.
Temperature scaling — one parameter, big win
Replace the softmax $p_c = e^{z_c} / \sum e^{z_{c'}}$ with $p_c^{(T)} = e^{z_c / T} / \sum e^{z_{c'} / T}$ at inference. Fit $T$ on a held-out validation set by minimising NLL. Tipically $T \in [1, 3]$ for over-confident networks; you recover most of the calibration without touching the weights.
Other recipes when temperature alone isn't enough: Platt scaling (logistic regression on logits, binary), isotonic regression (non-parametric monotone fit), histogram binning, vector / matrix scaling (per-class temperatures). Pick the simplest that works.
Four post-hoc calibrators, side by side
Temperature scaling is a one-parameter fix. Sometimes one parameter isn't enough. Here are the four post-hoc calibrators you'll meet in practice, fit on the same held-out validation set and then evaluated on the same test set:
- Temperature scaling. One scalar $T$. Cheap, accuracy-preserving. Most popular default.
- Platt scaling. Logistic regression on the max logit: $p = \sigma(a\,z_{\max} + b)$. Two parameters. Strong baseline for binary problems.
- Isotonic regression. Non-parametric monotone fit on the binned reliability curve. Many parameters, but reliably calibrates without distorting the ordering.
- Vector scaling. Per-class temperatures $T_c$ on logits before softmax. $C$ parameters; useful when over-confidence is class-dependent.
Why this matters
- Deployed alerting. A "high-risk" alert with 0.95 calibrated confidence is actionable; the same number from an over-confident model is just noise.
- Medical / safety-critical decisions. A model whose outputs feed treatment or operational choices must ship calibrated probabilities — otherwise downstream decisions are made on the wrong basis.
- Active learning + Bayes-Opt. Acquisition functions (BALD, EI) read confidence; broken calibration breaks every uncertainty-aware downstream choice.
- Conformal sandwich. Conformal prediction (the conformal article) gives a coverage guarantee but tighter intervals when the base model is well-calibrated. Calibrate first, conformal second.
Why neural nets miscalibrate in the first place
Guo et al. (2017) traced modern over-confidence to three things:
- Capacity. Bigger models can drive training NLL to zero by pushing logits to $\pm \infty$. That fits the training set perfectly with maximally-confident softmaxes; the held-out distribution lags. Test confidence ends up systematically too high.
- Weight decay reduction. Modern training uses much less weight decay than older models; without that implicit regulariser, logits drift larger.
- BatchNorm. Empirically correlated with worse calibration, possibly because per-batch statistics introduce stochasticity in logits that the model compensates by overcommitting on average.
The good news: temperature scaling fixes essentially all of this on i.i.d. test sets. The bad news: under distribution shift, temperature scaling alone is no longer enough — the optimal $T$ on the in-distribution validation set is wrong for the shifted test distribution. Ovadia et al. (2019) showed this empirically. Mitigations: train with mixup / label smoothing (intrinsic calibration), or use conformal prediction (which has a coverage guarantee under exchangeability assumptions that are still violated by shift, but less catastrophically).
Beyond classification — regression calibration
For regression, "calibrated" means: a 90% predictive interval should cover the true value 90% of the time. The reliability diagram is replaced by a coverage-vs-nominal plot:
The expected calibration error for regression is $\int_0^1 |\mathrm{coverage}(\alpha) - \alpha|\, d\alpha$. Tools to fix regression miscalibration:
- Quantile regression with pinball loss directly learns conditional quantiles without distributional assumptions.
- Conformalised quantile regression (CQR) wraps the quantile model in conformal prediction for a distribution-free coverage guarantee.
- Isotonic regression on the CDF. Fit a monotone transformation $\hat F(y|x) \mapsto F(y|x)$ that maps the model's CDF to the empirical one.
Reading list
- Guo, Pleiss, Sun, Weinberger (2017) — On Calibration of Modern Neural Networks. Defined ECE; introduced temperature scaling.
- Platt (1999) — Probabilistic outputs for SVMs. Platt scaling.
- Zadrozny & Elkan (2002) — Transforming Classifier Scores into Accurate Multiclass Probability Estimates. Isotonic.
- Ovadia et al. (2019) — Can You Trust Your Model's Uncertainty? The OOD calibration paper.
- Kuleshov, Fenner, Ermon (2018) — Accurate Uncertainties for Deep Learning Using Calibrated Regression.
- Niculescu-Mizil & Caruana (2005) — Predicting Good Probabilities With Supervised Learning. The classical calibrator-comparison paper.