When a Classifier’s Probability Can Be Trusted

A high accuracy does not mean the stated probability matches the observed frequency. A reliability diagram shows the gap.

When a Classifier’s Probability Can Be Trusted

A classifier can report 90 percent accuracy and still be wrong when it says "this example is class A with probability 0.8". Accuracy counts how many labels match. Calibration asks whether the stated probability matches the observed frequency. In a system that sets a threshold, raises an alarm, or hands a case to a person, the second measure does not replace the first. It stands beside it.

A reliability diagram is built as follows. Examples in the validation set are binned by the probability the model states. Each bin plots the average stated probability against the true positive rate in that bin. If the two match, the point sits on the diagonal. If the stated probability is above the observed rate, the point sits below the diagonal: the model looks more certain than the data. The opposite means the model is timid.

Guo, Pleiss, Sun and Weinberger showed in 2017 that modern neural networks can gain accuracy while their probabilities leave the diagonal. The paper measures the gap with expected calibration error: the average of the bin gaps, weighted by the number of examples. Accuracy at a single threshold cannot stand in for that number.

Calibration is meaningless if the validation set is not separate from the training set. An example that updated the weights and also entered the curve does not measure probability on new data. When the field distribution leaves the validation set, the curve is drawn again. Drawing it once and keeping it for the life of the product freezes the probability.

On a FenergyTech model job the curve is drawn on the validation set before a threshold is set. If the curve leaves the diagonal clearly, the raw percent is not used as the alarm text.

A small count shows the job. Ten bins. In the bin where the model said 80 percent, forty of a hundred examples are actually positive. The stated probability is twice the observed rate. The point sits below the diagonal. The expected calibration error in Guo and colleagues weights that gap by the number of examples in the bin. A bin of a hundred pulls harder than a bin of ten. Accuracy at one threshold does not carry that weight. Accuracy can be high at 0.5 while everything above 0.8 is inflated.

The number of bins moves the result too. Two bins average the gap away. A hundred bins leave bins empty and produce noise. The size of the validation set is written down, and the bin count is chosen from it. Without the size, the curve is a line that looks tidy on a slide.

The curve is not drawn once and frozen with the product. When the field input leaves the validation set, the same bins give another rate. The curve is drawn again at that departure. The raw percent stays in the alarm text only while the curve sits near the diagonal.

Sources: C. Guo, G. Pleiss, Y. Sun, K. Q. Weinberger, "On Calibration of Modern Neural Networks", Proceedings of the 34th International Conference on Machine Learning, PMLR 70, pp. 1321–1330, 2017.

Share:

Planning a similar project?

We can talk through how the topic in this article applies to your product.

More articles

Browse our other technical articles