Expected calibration error (ECE) is a metric that measures the average gap between a model’s confidence and its actual accuracy, computed by grouping predictions into confidence bins and taking a weighted mean of the absolute differences. A perfectly calibrated classifier has an ECE of zero: among all predictions made with 80 percent confidence, exactly 80 percent are correct.
Model evaluation in artificial intelligence has traditionally focused on whether predictions are right. ECE answers a different question: whether the stated probabilities can be trusted. This matters wherever a score drives a decision, such as triage in medicine, abstention in language models or risk thresholds in finance, because an overconfident model looks equally sure when it is wrong.
How expected calibration error is computed
ECE is computed from a held-out set of predictions in four steps. The standard version uses the top-label confidence, which is the highest predicted class probability, and compares it with whether that predicted class was correct.
- For each of
nexamples, record the confidence of the predicted class and whether the prediction was correct. - Split the interval from 0 to 1 into
Mbins, most often 15 equal-width bins. - For each bin, compute the mean confidence and the accuracy of the examples that fall into it.
- Sum the absolute differences between accuracy and confidence, each weighted by the bin’s share of examples.
In formula form, ECE equals the sum over bins of (|B_m| / n) * |acc(B_m) - conf(B_m)|. The result is usually reported as a percentage between 0 and 100. Values below about 2 percent are generally considered well calibrated for image classifiers, while uncalibrated deep networks often show 5 to 15 percent, although these ranges depend on the task, the number of classes and the binning scheme.
The bins are the same ones drawn in a reliability diagram, which plots accuracy against confidence. ECE condenses that diagram into one number: it measures how far the bars deviate from the diagonal, weighted by how many predictions each bar contains.
Variants of the calibration metric
Because the basic estimator has known weaknesses, several variants of ECE are in common use. Reporting which variant was used is essential, since numbers from different variants are not comparable.
| Variant | What changes | When it helps |
|---|---|---|
| Equal-width ECE | Fixed bins of equal width | Standard baseline in most papers |
| Adaptive ECE | Bins hold equal numbers of examples | Confidence clusters near 1.0 |
| Maximum calibration error | Worst bin instead of weighted mean | Safety-critical settings |
| Classwise ECE | Computed per class and averaged | Rare classes matter |
| Smooth or kernel ECE | Kernel estimate replaces hard bins | Small evaluation sets |
Modern networks place most predictions above 0.9 confidence, so equal-width bins leave many bins nearly empty. Equal-mass binning spreads examples evenly and usually gives a more stable estimate with lower variance.
How ECE relates to other evaluation metrics
ECE measures calibration only, not overall predictive quality. It should be read together with accuracy and a proper scoring rule such as the Brier score or log loss, which reward both calibration and the ability to separate classes.
| Metric | What it measures | Key property |
|---|---|---|
| Expected calibration error | Confidence-accuracy gap | Not a proper scoring rule |
| Brier score | Mean squared error of probabilities | Proper; mixes calibration and sharpness |
| Negative log-likelihood | Log loss on true labels | Proper; punishes confident errors heavily |
| Accuracy | Share of correct predictions | Ignores probability values |
| AUC | Ranking quality across thresholds | Unaffected by monotonic recalibration |
The most important caveat follows from the first row: a model that always predicts the base rate can reach an ECE near zero while being useless. A low ECE never proves a good model; it only shows that the confidence values mean what they say.
Reducing calibration error in practice
Calibration is usually improved after training with a small held-out calibration set, without retraining the model. The simplest and most widely used method is temperature scaling, which divides the logits by one learned scalar.
| Method | How it works | Trade-off |
|---|---|---|
| Temperature scaling | Divides logits by one fitted value | Keeps accuracy; limited flexibility |
| Platt scaling | Fits a logistic curve to scores | Suited to binary tasks |
| Isotonic regression | Fits a monotone step function | Flexible but needs more data |
| Histogram binning | Replaces scores with bin accuracy | Coarse probability output |
| Label smoothing in training | Softens training targets | Can hurt later recalibration |
Temperature scaling does not change the ranking of classes, so accuracy stays the same while ECE often drops by a large margin. Calibration methods must be fitted on data separate from the test set; otherwise the reported ECE is optimistically biased.
Limitations and common mistakes
ECE is easy to compute but also easy to misread. Several pitfalls appear repeatedly in published evaluations.
- Bin sensitivity: changing the number of bins from 10 to 20 can change the value noticeably and even reverse model rankings.
- Small-sample bias: with few examples per bin, the estimator is biased upward, so small test sets overstate miscalibration.
- Top-label blindness: standard ECE ignores the probabilities of non-predicted classes.
- Distribution shift: a model calibrated on validation data can become overconfident on shifted inputs.
- Undocumented settings: results without the bin count and binning scheme cannot be reproduced.
For language models, ECE can be computed on answer probabilities or on verbalized confidence, but the two often disagree. Instruction-tuned and preference-tuned models are frequently less calibrated than their base models, which makes calibration a standard check in LLM evaluation.
The simple explanation
Imagine a weather forecaster who says there is a 70 percent chance of rain. If it rains on about 70 of every 100 such days, the forecaster is well calibrated. If it rains on only 40 of them, the forecaster is too confident.
Expected calibration error checks the same thing for an AI model. It groups the answers by how sure the model claimed to be. Then it compares that with how often the model was right. The result is one number for the gap. Zero means the model’s confidence can be taken at face value.
How it is used in practice
A hospital team evaluates an image classifier that flags suspicious skin lesions for review. On a held-out set of 5,000 images, the model reaches 91 percent accuracy, but its 15-bin ECE is 8.4 percent: predictions made with 95 percent confidence are correct only about 84 percent of the time.
The team fits temperature scaling on a separate calibration set of 1,000 images. Accuracy stays at 91 percent, while ECE falls to 1.6 percent and the reliability diagram moves close to the diagonal. Clinicians can now rely on the scores to set a referral threshold, sending every case below 90 percent confidence to a dermatologist. The team also checks ECE on images from a second clinic to detect calibration loss under distribution shift before deployment.