Are model confidence scores calibrated? Expected calibration error, worked

Abstract

A model that says it is 90 percent sure should be right about 90 percent of the time. This paper measures the gap with expected calibration error, reads it off a reliability diagram, and compares three ways to correct it, on synthetic predictions where the true answer is known.

A model that reports a confidence should be right about as often as it claims. Calibration is the property that makes the number usable: a 0.8 that means 0.8 lets someone decide when to check an answer. This paper measures calibration on a synthetic set of predictions, defines the standard summary, shows the diagnostic plot, and compares three corrections. The data is built so that the true probability of being right is known, which makes each claim checkable.

The setup

We simulate 4,000 predictions. Each has a stated confidence c drawn uniformly from 0.5 to 1.0. The chance that the prediction is correct is c raised to the power 2.2. So a stated 0.9 is right about 0.9^2.2 = 0.79 of the time. The model is overconfident, by construction. Overall accuracy is 55.6 percent.

The data is split in half. The first half is used to fit any correction, and the second half is used only to measure the result. This matters: a correction measured on the data it was fitted to looks better than it is.

The summary statistic

Sort predictions into ten equal-width confidence bins. For bin b, with n_b predictions, compare the mean confidence with the observed accuracy:

ECE = sum over bins b of (n_b / N) * | accuracy_b - confidence_b |

Each bin contributes its gap, weighted by how many predictions it holds. A perfectly calibrated model scores 0.

A worked bin

Take the bin from 0.80 to 0.85. It holds 405 of the 4,000 predictions, so its weight is 405 / 4000 = 0.101. The mean confidence in the bin is 0.825. The observed accuracy is 0.644. The gap is 0.180. The bin’s contribution to ECE is 0.101 * 0.180 = 0.018. Summing the contributions of all ten bins gives the ECE of 0.193.

The number is an average, so it hides the sign of each gap. Here every bin is overconfident, which the table below shows.

bin count mean confidence accuracy gap
0.50–0.55 463 0.525 0.246 0.279
0.55–0.60 374 0.575 0.275 0.300
0.60–0.65 410 0.626 0.366 0.260
0.65–0.70 380 0.676 0.403 0.273
0.70–0.75 373 0.726 0.509 0.217
0.75–0.80 373 0.775 0.542 0.233
0.80–0.85 405 0.825 0.644 0.181
0.85–0.90 421 0.874 0.765 0.109
0.90–0.95 408 0.925 0.865 0.060
0.95–1.00 393 0.975 0.954 0.021

The gap is largest in the low-to-middle bins, where the model is often wrong yet still claims 55 to 70 percent, and it shrinks toward the top of the range.

How sure is 0.193?

Resampling the 4,000 predictions 1,000 times gives a 95 percent interval of 0.179 to 0.206. The gap is well away from zero, so the overconfidence is not a sampling accident. The width of the interval also shows what the diagnostic can resolve: differences of a percentage point between two models would need a much larger sample to trust.

The reliability diagram

The standard picture plots observed accuracy against stated confidence. A calibrated model lies on the diagonal, marked with dots below. The # symbols are the observed accuracy in each bin.

  1.00 |                                      ..
  0.95 |                                  ...#
  0.91 |                               ...
  0.86 |                           ....  #
  0.82 |                        ...
  0.77 |                    ....     #
  0.73 |                ....
  0.68 |             ...
  0.64 |         ....            #
  0.59 |      ...
  0.55 |  ....               #
  0.50 |..                #
       +----------------------------------------
          0.50        0.75         1.00  stated confidence
legend: # = observed accuracy per bin, . = perfect calibration

Every # sits below its dot. That is the signature of overconfidence, and it is visible at a glance even before reading the table.

Three corrections, measured on held-out data

Each correction is fitted on the first half of the data and scored on the second half.

method held-out ECE held-out NLL
none 0.188 0.654
temperature scaling (one parameter, T = 2.09) 0.143 0.612
Platt scaling (two parameters, a = 1.18, b = -1.22) 0.014 0.554
equal-width binning (ten bins, fitted accuracy per bin) 0.015 0.559

NLL is the negative log-likelihood, where lower is better. Each row answers a different question.

Temperature scaling divides the logit by one number. It helps, but it leaves most of the gap in place, because this model’s error is not a constant rescaling of its logit. Its accuracy is a power of its confidence, and no single temperature reproduces that curve. Platt scaling fits a slope and an intercept on the logit, and that is enough to remove almost all of the measured gap. Binning does nearly as well, but it needs enough predictions in every bin to estimate each bin’s accuracy, which 4,000 items barely supplies.

The practical rule is to check the reliability diagram after any correction, not only the summary number. Temperature scaling lowers ECE from 0.188 to 0.143, which sounds like progress, while the curve in the diagram is still visibly off. Platt scaling passes both checks here, but it was chosen because this synthetic model has a simple shape. A real model’s miscalibration may not have one.

Limits

These results come from a synthetic model where the true probability is known. Real models are miscalibrated in ways that depend on the question, the prompt and the topic, and a correction fitted on one distribution can break on another. The method is portable, the numbers are not.

Conclusion

Expected calibration error turns the gap between stated confidence and observed accuracy into one number, and the reliability diagram shows where that gap sits. In this example, one parameter removes only a quarter of the error, and two parameters remove nearly all of it. Fit any correction on one half of your data, score it on the other, and read the diagram as well as the number.