← Explainer Library

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.

Prelude

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 slogan. Accuracy and calibration are independent. A model can be 90% accurate and badly miscalibrated; a model can be 60% accurate and perfectly calibrated. Any safety-relevant deployment cares about both.
Step 1

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.

Step 2

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.

step 0 accuracy ECE
Decision boundary on test data
Reliability diagram
Metrics over time
What to watch for. For the first ~50 steps accuracy and ECE both improve. Past ~150 steps, accuracy plateaus but the bins drift below the diagonal — the model has become over-confident. Slide T from 1 toward ~2 and watch the bins migrate up to the diagonal while accuracy stays exactly the same. That's temperature scaling.
Step 3

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.

Step 3 ½

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:

Reliability diagrams for the four post-hoc calibrators on the same trained classifier. ECE shown under each panel.
The verdict. Temperature scaling almost always wins on accuracy + simplicity + parameter count. Isotonic and vector scaling can edge ahead on severely-miscalibrated multi-class problems but cost more parameters. Platt is binary-only and largely subsumed by temperature.
Step 4

Why this matters

Final takeaway. Every deployed model should ship with a reliability plot and an ECE number. It's 30 lines of code and it tells you whether the confidences mean anything. Temperature scaling is the cheapest possible repair if they don't.
Step 5

Why neural nets miscalibrate in the first place

Guo et al. (2017) traced modern over-confidence to three things:

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).

Step 6

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:

Step 7

Reading list