Lensa ML
Lensa ML

Model Calibration

Step 1 of 6: What Confidence Promises

90% sure should mean right 90% of the time

Confidence band90% to 100%
220 of 2000 test predictions, placed by confidence (synthetic data)00.20.40.60.81correctwrongconfidence = top softmax probabilityClaimed99.2%Correct93.5%
Predictions in band
1399
Average confidence
99.2%
Fraction correct
93.5%

In this band the model claims 99.2% on average but is right 93.5% of the time, 5.7 pts short. A calibrated model would land the two bars at the same length.

Drag Confidence band from the lowest band to 90% to 100% and compare the two bars. Confidence here is the largest softmax probability, so with 10 classes it can never fall below 10%. Formally, a model is calibrated when P(correct | confidence = p) = p for every p. No finite test set can check that exactly, because almost no two predictions share the same confidence. Grouping nearby confidences into bands, as the slider does, is the practical workaround, and the next step turns those bands into a full chart.

Step 2 of 6: Reliability Diagram

Accuracy against confidence, bin by bin

Number of bins10
accuracyoverconfidentunderconfidentperfect00.250.50.75100.20.40.60.81confidence (gray: number of predictions)accuracy
Bins with data
8 of 10
Fullest bin
70%
Largest gap
34.6 pts

Every bar sits below the diagonal. The red strips show the model claiming more than it delivers, up to 34.6 pts in the 60% to 70% bin.

Drag Number of bins from 2 to 20 and watch the gray count bars under the diagram. Equal-width bins on a modern network leave most predictions in the top bin: here about 70% of the 2,000 land between 0.9 and 1. Some libraries use equal-mass bins instead, with the same number of predictions in each, so no bar rests on a handful of points. Reliability diagrams date back to weather forecasting, where they checked whether "70% chance of rain" came true 70% of the time.

Step 3 of 6: Expected Calibration Error

A weighted average of the gaps

Number of bins10
Click a bin to inspect its share of ECE00.250.50.75100.20.40.60.81confidence (gray: number of predictions)accuracyECE = sum of the segments11.32%
ECE
11.32%
Bin weight n_b/N
70.0%
Bin gap
5.7 pts
Contribution
4.02%

The 90% to 100% bin adds the most: 70.0% of predictions × 5.7 pts gap = 4.02% of the 11.32% total. The largest single gap, the MCE, is 34.6 pts.

Click a bin, then move Number of bins and watch the ECE readout. It stays at 11.32% for every bin count, because every gap here has the same sign. When the model is overconfident everywhere, ECE equals mean confidence minus accuracy: 87.0% against 75.6%. Bin counts change ECE only when some bins are over and others under. Naeini et al. introduced ECE in 2015, and Guo et al. used 15 bins. ECE also ignores the classes that were not the top prediction.

Step 4 of 6: Overconfident Networks

Stretched logits bend the diagram

Overconfidence γ (logit multiplier)γ = 2.00
accuracyoverconfidentunderconfidentperfect00.250.50.75100.20.40.60.81confidenceaccuracyECE as γ changes (10 bins)0.511.522.53γ (1 = calibrated by construction)
Accuracy
75.6%
Mean confidence
87.0%
ECE
11.32%
NLL
0.908

At γ = 2.00 the logits are stretched. Mean confidence rises to 87.0% while accuracy stays at 75.6%, and ECE grows to 11.32%.

Drag Overconfidence γ from 0.5 to 3 and follow the dot along the ECE curve. Guo et al. compared a 1998 LeNet with a 2016 ResNet on CIFAR-100: the older network was close to calibrated, the newer one far more accurate and badly overconfident. Greater depth and width, batch normalization, and less weight decay all pushed confidence up. Training keeps lowering the log loss on the training set by growing the logits after almost every example is already classified correctly, which is the same stretch γ applies here.

Step 5 of 6: Temperature Scaling

One parameter fitted on validation data

Temperature T (logits ÷ T)T = 1.00
Test set, 10 bins00.250.50.75100.20.40.60.81confidenceaccuracyValidation NLL1.049Test ECE11.32%0.51234T (dashed: fitted T*)
Validation NLL
1.049
Test ECE
11.32%
Accuracy
75.6%
Fitted T*
2.03

At T = 1.00 the softmax is still too sharp, so bars sit below the diagonal and ECE is 11.32%. Raise T toward 2.03 to soften it.

Press Fit T on validation, then nudge Temperature T either side and watch both curves. T is chosen by minimizing NLL on a held-out validation set, never on test data, and the fit lands at T* = 2.03, close to the γ = 2 that made this model overconfident. NLL is convex in 1/T, so a one-dimensional search finds it in milliseconds. Guo et al. found this single parameter matched or beat methods with many more parameters on most of their datasets. It fixes a uniform stretch, not a bias that differs by class.

Step 6 of 6: Calibration in Practice

Platt, isotonic and decision thresholds

Act only at confidence of at least90%
accuracyoverconfidentunderconfidentperfect00.250.50.75100.20.40.60.81confidence (gray: number of predictions)accuracyact →
ECE
11.32%
Brier score (top label)
0.1252
Predictions kept
1399 (70%)
Errors expected / made
11 / 91

The rule keeps 1399 predictions. Their confidences add up to about 11 expected errors, but 91 are wrong, 80 more than the model promised.

Switch between Uncalibrated, Temperature, Platt and Isotonic, then set the threshold to 90%. The Brier score is the mean of (p − correct)^2, here applied to the top label only; it drops from 0.125 uncalibrated to about 0.100 after any of the three fixes. Platt scaling fits a two-parameter logistic curve and was first used for SVM scores. Isotonic regression fits any increasing step function, so it needs more validation data and can overfit with a few hundred examples. All three keep the ranking of predictions unchanged.

What is model calibration in machine learning?

A model is calibrated when its predicted probabilities match how often it is right. Among all predictions made with 80% confidence, a calibrated classifier is correct about 80% of the time. Accuracy measures whether the top answer is right, while calibration measures whether the stated confidence can be trusted, and a model can score well on one and badly on the other.

Calibration matters wherever a probability drives a decision. Medical triage systems refer low-confidence cases to a doctor, fraud filters block a payment above a risk score, and self-driving stacks weigh detections by confidence. Ensembles and cost-sensitive rules both assume the probabilities are honest. Large language models raise the same question when they answer a question or abstain, since a confidence score is only useful if 90% means right nine times in ten.

Key ideas

  • A calibrated model is right about p of the time on the predictions it makes with confidence p.
  • A reliability diagram bins predictions by confidence and plots accuracy against the diagonal.
  • Expected calibration error is the gap in each bin weighted by the share of predictions in it.
  • Modern deep networks tend to be overconfident even when their accuracy is high.
  • Temperature scaling divides the logits by one fitted constant and never changes the predicted class.
  • Platt scaling and isotonic regression learn a mapping from raw scores to calibrated probabilities on held-out data.

Common questions

Does calibration change a model's accuracy?

Temperature scaling, Platt scaling and isotonic regression are all monotonic, so the top class and the ranking of examples stay the same and accuracy is unchanged. Isotonic regression can create ties, which slightly affects ranking metrics such as AUC. Methods that change the training itself, like label smoothing or mixup, can move both accuracy and calibration.

Is a lower log loss the same as better calibration?

Not exactly. Log loss and the Brier score are proper scoring rules, and both reward calibration and sharpness, meaning confident predictions that turn out right. A model can lower its log loss by being more accurate while staying miscalibrated. ECE isolates calibration, but a model that predicts the base rate for every example has zero ECE and no usefulness.

Are large language models calibrated?

Kadavath et al. found that large pretrained models are fairly well calibrated on multiple-choice questions when the answer options are presented clearly. Fine-tuning for chat with human feedback often makes them more overconfident, a drop the GPT-4 technical report also showed. Confidence stated in words, such as "I am 90% sure", is usually less reliable than the probability the model assigns to its answer tokens.

Do I need to recalibrate after the data changes?

Yes, calibration holds only for data like the set it was fitted on. Under distribution shift, accuracy usually drops faster than confidence, so a model calibrated in the lab becomes overconfident in production. Recalibrating on recent labeled data is cheap because only one or two parameters change.

Related explainers

References

  1. Guo et al. (2017), "On Calibration of Modern Neural Networks"
  2. Naeini, Cooper & Hauskrecht (2015), "Obtaining Well Calibrated Probabilities Using Bayesian Binning"
  3. Niculescu-Mizil & Caruana (2005), "Predicting Good Probabilities with Supervised Learning"
  4. Kadavath et al. (2022), "Language Models (Mostly) Know What They Know"

Last updated