A classifier that says it is 90% sure should be right about 90% of the time. That sounds like a low bar, and yet most modern neural networks fail it badly. They are routinely 99% confident and wrong, or 60% confident and right almost every time. Their accuracy can be excellent while their confidence is meaningless. That gap matters whenever a prediction drives a decision: triage in a clinic, a loan approval, a self-driving car deciding whether to hand control back to a human. In all of these, the number attached to the prediction is itself a prediction, and it needs to be right.

This article is about calibration: what it means, why deep networks are miscalibrated, how to measure it properly, and how to fix it, both after training and during it.

What calibration actually means

Take a classifier that outputs a probability distribution over classes. Let p^​ be the confidence it assigns to its predicted class Y^ . The classifier is perfectly calibrated when, over all the examples where it reports confidence p , it is correct a fraction p of the time:

P(Y=Y^∣p^​=p)=pfor all p∈[0,1]

Calibration is a property of the confidence scores, not of the predictions. A model can be perfectly accurate and badly calibrated (always 51% confident when it is always right), and it can be perfectly calibrated and useless (always predicting the base rate). Accuracy answers "how often are you right?". Calibration answers "when you say you are this sure, how often are you right?". Both questions matter, and they are independent.

A useful way to see the distinction is to separate two kinds of uncertainty. Aleatoric uncertainty is noise in the world itself: overlapping classes, ambiguous images, label noise. No model can remove it, and a calibrated model reports it honestly. Epistemic uncertainty is ignorance about the right model, which shrinks with more data. A miscalibrated network typically understates both. It reports near-certainty where the data is genuinely ambiguous, which is exactly the situation where an honest "I do not know" is most valuable.

Why modern networks are miscalibrated

Classical models such as logistic regression and naive Bayes were often reasonably calibrated almost by construction. Logistic regression is trained on the log loss, which is a strictly proper scoring rule, and its capacity is limited. Deep networks changed the picture. The influential 2017 study by Guo and co-authors showed that modern architectures such as ResNets and DenseNets are systematically overconfident, and that the problem got worse as models got deeper and wider, even as accuracy improved.

Four mechanisms drive this:

Negative log-likelihood rewards overconfidence. The training loss is:

LNLL=−n1​∑i=1nlogp^​i,yi​​

Minimising this loss on the training set pushes the probability of the correct class toward 1, which pushes the logits apart without bound. Nothing in the loss penalises a logit gap of 20 versus a gap of 5 once the example is classified correctly. The optimiser keeps growing the logits long after the decision boundary has settled, and confidence saturates at 0.999 or higher. Weight decay is the main force pushing back, which is one reason that regularisation strength affects calibration so strongly.

Capacity lets the model memorise. A network with enough parameters can fit the training labels almost perfectly, including the noisy ones. Once training accuracy approaches 100%, the loss can only fall further by making the correct-class probability even closer to 1, so the model learns to be extremely confident on points it has memorised. That confidence does not transfer to unseen data, where the same inputs would deserve much more modest probabilities.

Batch normalisation changes the geometry of confidence. Batch normalisation rescales activations and interacts with weight decay in a way that effectively increases the scale of the weights. The empirical finding is consistent: removing batch normalisation, or tuning its interaction with regularisation, often improves calibration. The mechanism is still debated, but the pattern is robust across architectures.

The loss is not the metric. Accuracy only cares about the argmax. Calibration cares about the whole distribution. A training objective that only rewards the argmax leaves the rest of the distribution unconstrained, and gradient descent fills that vacuum with whatever makes the loss smallest, which is extreme confidence.

Measuring calibration

You cannot fix what you do not measure, and the obvious summary statistics are misleading. Mean confidence tells you nothing on its own. The standard tool is the reliability diagram: bin predictions by confidence, then plot the accuracy within each bin against the bin's average confidence. A calibrated model sits on the diagonal. An overconfident model sits below it, and an underconfident one above it.

The most common single number is the Expected Calibration Error (ECE). Split the predictions into M bins by confidence, then take the weighted average of the gap between accuracy and confidence in each bin:

ECE=m=1∑M​n∣Bm​∣​∣acc(Bm​)−conf(Bm​)∣

where Bm​ is the set of examples in bin m , acc(Bm​) is their accuracy, and conf(Bm​) is their mean confidence. ECE is simple and interpretable, but it has flaws worth knowing. With fixed-width bins, most predictions land in the top bin, so the low-confidence region is estimated from almost no data. With equal-mass bins (the same number of examples per bin) the estimate is more stable, and that variant is often called adaptive ECE. The choice of bin count changes the number, so always report it alongside the binning scheme.

Two other metrics deserve a place in your toolkit. The Brier score measures the mean squared error between the predicted probabilities and the one-hot labels:

BS=n1​i=1∑n​k=1∑K​(p^​ik−yik)2

Unlike ECE it uses the whole distribution, not just the top class, and it decomposes into a calibration term plus a refinement term, so it rewards both honest confidence and sharp predictions. The maximum calibration error (MCE) is the worst bin gap rather than the average, which is the right number when a single overconfident region is dangerous even if the average looks fine.

A common mistake is to report calibration on the training set, or on the same validation set used to fit the calibration method. Calibration must be measured on held-out data that played no part in fitting the recalibration, or the numbers will look far better than they are.

Fixing it after training: recalibration

The cheapest and most reliable fix is post-hoc recalibration: keep the trained model, and learn a small mapping from its raw outputs to calibrated probabilities on a held-out validation set. The ranking of predictions never changes, so accuracy is untouched. Only the confidence values change.

Temperature scaling is the simplest method that works well, and it is the one to try first. Take the logits z and divide them by a single positive scalar T before the softmax:

q^​i​=∑j​exp(zj​/T)exp(zi​/T)​

A temperature above 1 softens the distribution, pulling extreme confidences back toward uniform. A temperature below 1 sharpens it. You fit T by minimising the negative log-likelihood on a validation set, which is a one-dimensional optimisation that takes seconds. Because it is a single parameter, it barely overfits, and because it is a monotonic rescaling of the logits, the predicted class never changes. In practice, temperature scaling often recovers most of the calibration that a more elaborate method would, and it is the method used in production more than any other.

Platt scaling fits a logistic regression on the model's outputs, and generalises temperature scaling to a full affine map. It has more parameters, so it can correct asymmetric miscalibration, but it needs more validation data to avoid overfitting.

Isotonic regression fits a monotone step function mapping raw confidence to calibrated probability. It is non-parametric and flexible, but it can overfit badly on small validation sets, and its piecewise-constant output makes it a poor choice when you need smooth probabilities.

Histogram binning is the simplest of all: assign each confidence bin its empirical accuracy as the calibrated probability. It is easy to understand and hard to get wrong, but it throws away the ordering information inside each bin.

The practical rule: start with temperature scaling. Move to Platt scaling or isotonic regression only if the reliability diagram shows that a single temperature cannot straighten the curve, and only with a validation set large enough to support the extra parameters.

Fixing it during training

Post-hoc methods correct the symptoms. A few training-time choices address the cause, and they stack well with temperature scaling on top.

Label smoothing replaces the one-hot target with a mixture of the true label and the uniform distribution:

y~​k​=(1−ϵ)yk​+Kϵ​

With ϵ=0.1 , the model is never rewarded for pushing the correct-class probability above 0.9, so the logits stop growing and confidence stays in a sane range. Label smoothing reliably improves calibration, though it can slightly hurt accuracy on tasks where the classes are genuinely separable.

Mixup trains on convex combinations of pairs of examples and their labels. The model learns to assign intermediate probabilities to interpolated inputs, which smooths the confidence landscape and prevents the sharp, overconfident transitions between classes that ordinary training produces.

Focal loss down-weights examples the model already classifies confidently, which stops the optimiser from spending its effort making easy examples even more certain:

FL(pt​)=−(1−pt​)γlog(pt​)

where pt​ is the probability assigned to the true class and γ controls how strongly easy examples are down-weighted. It was designed for class imbalance, but it also improves calibration, particularly on long-tailed data.

Ensembles and Bayesian methods average over many models or many parameter settings, and the average of several overconfident models is typically better calibrated than any single one. A deep ensemble of five networks is still one of the strongest calibration methods available, at five times the cost. If you can afford it, it is worth it.

A worked example: fitting a temperature

Here is the whole procedure in PyTorch. Train your model normally, then hold out a validation set and fit one scalar:

import torch import torch.nn as nn # logits: (n, num_classes) tensor from the trained model on validation data # labels: (n,) tensor of true class indices temperature = nn.Parameter(torch.ones(1)) optimizer = torch.optim.LBFGS([temperature], lr=0.1, max_iter=50) def closure(): optimizer.zero_grad() loss = nn.functional.cross_entropy(logits / temperature, labels) loss.backward() return loss optimizer.step(closure) print("Fitted temperature:", temperature.item()) # At inference time, divide logits by the fitted temperature before softmax. calibrated_probs = torch.softmax(logits / temperature, dim=1) 

Two details matter. First, fit the temperature on data the model did not train on; fitting it on the training set will give you a temperature near 1, because the model is already confident and correct there. Second, refit whenever the model or the data changes. A temperature fitted on one distribution is not valid on another, which leads directly to the limitations below.

If you work in scikit-learn, CalibratedClassifierCV wraps the same idea: it fits your classifier, then fits a sigmoid (Platt) or isotonic calibrator on held-out folds, and you can compare the ECE before and after with a reliability diagram from CalibrationDisplay.

Limitations and common pitfalls

Calibration is not a property you fix once and forget. These are the traps that catch people in practice:

Calibration is not accuracy, and it does not imply accuracy. A model that always predicts the class prior is perfectly calibrated and useless. Report accuracy and ECE together, and never optimise one while ignoring the other.

Distribution shift breaks calibration first. A model calibrated on one hospital's patients, one camera's images, or one time period can be badly miscalibrated on the next. Temperature scaling assumes the validation distribution matches deployment, and when that assumption fails, the recalibration can be worse than nothing. Under shift, conformal prediction or explicitly modelling the shift is usually a better investment than recalibration.

Calibrating on the test set is cheating. Every calibration method has parameters, and fitting them on the data you report on gives an optimistic estimate. Keep a separate calibration set, or use cross-fitting, and report the ECE on data that touched neither training nor calibration.

Top-label calibration is not full calibration. ECE measures the confidence of the predicted class only. A model can be top-label calibrated while its second- and third-ranked probabilities are nonsense. If downstream decisions use the full distribution, use the Brier score or a class-wise ECE, which measures calibration separately for each class.

Calibration interacts with the decision threshold. In a system that acts only above a confidence threshold, what matters is calibration near that threshold, not the global ECE. Check the reliability diagram in the region where decisions are actually made, and consider selective prediction: abstaining below a confidence level is only meaningful if the confidence is calibrated.

The takeaway

Confidence is a claim about the world, and it should be held to the same standard as the prediction itself. Modern networks are accurate and overconfident, because the loss they optimise rewards certainty without bound and their capacity lets them memorise their way to it. Measure calibration with reliability diagrams and ECE on held-out data, fix it cheaply with temperature scaling, and fix it more deeply with label smoothing, mixup, or ensembles when you can afford to. And remember that calibration is a property of a model on a distribution, not of a model in the abstract: it needs to be rechecked every time the data changes.

Connect with me on LinkedIn: linkedin.com/in/umeshtharukaofficial