Model Calibration

Machine Learning
Introduced by
Platt; Guo et al.
Year
2017
Type
Post-hoc probability correction technique
Family
Trustworthy ML

What does it do?

Model calibration is a post-hoc procedure that adjusts the probability outputs of a trained classifier so that predicted confidence matches observed accuracy.

A classifier is perfectly calibrated when, among all predictions made with confidence p, a fraction p of them are correct. Guo et al. (2017) reported that modern neural networks trained with cross-entropy loss tend to be overconfident, and proposed temperature scaling as a simple remedy.

The intuition behind the method

Imagine a weather forecaster who says 'there is a 90% chance of rain' on 100 different days. If only 60 of those days actually see rain, the forecaster is overconfident. Calibration is like recalibrating the forecaster's scale so that when they say 90%, the rain rate truly is 90%. For a neural network, this means stretching or compressing its raw confidence scores until the numbers on the label faithfully reflect how often the network is right.

History

The methods described on this page, namely temperature scaling, ECE and NLL-based fitting of T, follow Guo et al. (2017). That study examined the calibration of modern neural networks, reported that they tend to be overconfident under standard cross-entropy training, and proposed temperature scaling as a simple remedy.

When to use it

Choose calibration when predicted probabilities are used at face value, for example when a probability is compared with a fixed decision threshold, used in an expected-cost calculation, or combined across models, as in medical risk stratification or cost-sensitive fraud scoring. It matters most for deep neural networks, which Guo et al. (2017) reported to be overconfident under standard cross-entropy training. Do not expect calibration to repair a model with poor ranking, and do not rely on a fitted mapping after distribution shift, because it is estimated on a held-out set from the calibration distribution. Calibration is unnecessary when only the predicted class matters, since temperature scaling does not change it. If prediction sets with coverage guarantees are needed instead of point probabilities, consider conformal prediction.

Limitations and considerations

  • The temperature is fitted on a held-out set, so a small calibration set yields an unstable estimate of T.
  • A single global T assumes one correction suits all confidence levels and classes; class-specific or region-specific miscalibration is not captured.
  • ECE depends on the number of bins M and their boundaries, so values computed with different binning are not directly comparable.
  • Calibration rescales confidence but adds no discriminative information; a classifier with weak ranking remains weak even when its probabilities are better aligned.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Temperature scaling has a single parameter T, and dividing all logits by the same positive value leaves the predicted class unchanged, so calibration does not alter top-1 predictions.
  • ECE gives one scalar summary of miscalibration that can be compared before and after correction, although it should be read alongside a reliability diagram.
  • Because it operates on logits or scores, calibration can be applied to an already-trained classifier without retraining it.
  • Calibrated probabilities are closer to observed frequencies on the calibration data, so they can be used in threshold and expected-cost calculations, provided the deployment data resemble the calibration data.

Applications

  • Clinical risk models whose predicted probabilities are compared against treatment thresholds.
  • Fraud or credit-risk scoring where probabilities feed accept/reject rules with asymmetric error costs.
  • Combining outputs from several classifiers on a common probability scale before aggregation.
  • Reporting reliability diagrams and ECE as part of model validation before deployment.

How it works

How it works

1

For each validation example, take the maximum softmax probability across classes as the model's reported confidence. This scalar is the raw input to the calibration pipeline and states how certain the model claims to be about its top prediction. Calibration in this sense is top-label: it concerns the confidence of the predicted class and does not guarantee that every class probability is calibrated.

Formula
\hat{p}_i = \max_c \, \hat{\sigma}_c(\mathbf{x}_i)
2

Partition predictions into M equal-width bins by confidence. For each bin, compute the gap between mean confidence and accuracy, then take the average of these gaps weighted by bin size. The resulting Expected Calibration Error (ECE) is the main diagnostic; lower values indicate closer agreement between predicted probabilities and observed frequencies. Its value depends on the choice of M and the bin boundaries, so report both with any ECE value to allow comparison and reproduction.

Formula
\mathrm{ECE} = \sum_{m=1}^{M} \frac{|B_m|}{n} \left| \mathrm{acc}(B_m) - \mathrm{conf}(B_m) \right|
3

Divide the pre-softmax logit vector by a single scalar T > 0 before applying the softmax. When T > 1 the distribution is flattened, which reduces overconfidence; when T < 1 it is sharpened. Because every logit is divided by the same positive T, their order is unchanged, so the predicted class does not change.

Formula
\hat{q}_i = \max_c \, \sigma_{\mathrm{SM}}\!\left(\mathbf{z}_i / T\right)_c, \quad T > 0
4

Choose T* by minimising the negative log-likelihood (NLL) of the labelled held-out validation set. This is a search over one scalar parameter, carried out by gradient-based optimisation or a line search. The fitted T* is then fixed and applied to all subsequent predictions.

Formula
T^* = \arg\min_{T} \, \mathcal{L}_{\mathrm{NLL}}\!\left(\sigma_{\mathrm{SM}}(\mathbf{z}/T),\, y\right)

Common pitfalls

  • Fitting T on the training data gives an optimistic fit and a misleadingly low ECE; the parameter must be estimated on a separate validation set.
  • Calibrated confidence is not a full uncertainty estimate: it matches stated probabilities to observed accuracy but does not separate sources of uncertainty, such as label noise from model ignorance.
  • ECE is an average that can hide poor calibration in sparsely populated bins, so the reliability diagram should be inspected alongside the scalar.
  • A temperature fitted on one distribution can misstate confidence after distribution shift, because the mapping encodes the calibration data rather than the deployment data.

Frequently asked questions

Does calibration affect classification accuracy?

Temperature scaling does not change the predicted class, because dividing all logits by the same positive T preserves their order, so top-1 accuracy is unchanged. Calibration methods that are not of this form are not guaranteed to preserve the argmax, so check top-1 accuracy after fitting any such method.

How do I know if my model needs calibration?

Plot a reliability diagram: group predictions into confidence bins and plot mean confidence against empirical accuracy. A perfectly calibrated model follows the diagonal. Points below the diagonal, where accuracy is lower than stated confidence, indicate overconfidence; points above it indicate underconfidence. ECE summarises the average gap in one number. There is no universal cut-off for ECE, so set an acceptable level from the cost of errors in your application.

When should I use isotonic regression instead of temperature scaling?

Isotonic regression is a non-parametric, monotone mapping, so it can follow irregular miscalibration across the probability range. In common practice it is fitted on larger calibration sets, because a flexible mapping is harder to estimate reliably from few points. Temperature scaling, with one parameter, is often preferred when the calibration set is small or when a simple, interpretable correction is wanted. Consider isotonic regression when the reliability diagram shows an irregular pattern that a single temperature cannot follow.

Related methods

Sources

  1. Guo, C., Pleiss, G., Sun, Y., & Weinberger, K. Q. (2017). On calibration of modern neural networks. International Conference on Machine Learning, 1321–1330.

    Open publication reference