Probability Calibration › Example
Machine Learning from ScratchAll chapters Probability Calibration › ExampleSection view · Sections in this chapter5 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
A small numerical example makes the decomposition concrete and shows why calibration can improve proper scores without changing the ranking. Suppose a model produces ten predictions and we group them into two reliability bins. Every case in the high-score bin receives probability 0.9; four of its five cases are positive. Every case in the low-score bin receives probability 0.6; one of its five cases is positive. Using only bin means would not determine the original unbinned scores. We fit and score the illustrative mapping on these same ten cases to show the arithmetic; the later implementation uses separate calibration and test partitions.
| Bin | Mean predicted | Positives | Observed rate | |
|---|---|---|---|---|
| High | 5 | 0.9 | 4 | 0.8 |
| Low | 5 | 0.6 | 1 | 0.2 |
The raw Brier score is the average squared difference between each predicted probability and its outcome.
In the low bin, one case has outcome 1 and four have outcome 0:
The overall Brier score is
Now we decompose it. The reliability term is
The resolution term is
The uncertainty term is
where is the base rate, the fraction of positive cases in the full sample. So
which matches the direct Brier score. The expected calibration error is
The raw log loss is
Now apply an isotonic recalibration. The high bin maps to 0.8 and the low bin maps to 0.2, because those are the observed rates in the two monotone blocks. The calibrated Brier score becomes
The calibrated log loss becomes
Both proper scores improve substantially. The ranking, however, does not improve. There are four positive cases in the high bin and one positive case in the low bin, with one negative case in the high bin and four negative cases in the low bin. Pairing each positive with each negative gives 25 pairs. Predictions are tied within each bin both before and after this mapping. There are sixteen cross-bin pairs with the positive in the high bin and the negative in the low bin, four within-high-bin tied pairs, four within-low-bin tied pairs, and one cross-bin pair with the positive in the low bin and the negative in the high bin. Treating ties as one-half gives
The calibrated scores preserve this ranking, so AUC remains 0.8. This example shows the central distinction: calibration repairs the probability scale, while discrimination is about the ordering. That is why we inspect both calibration and ranking.
The additive decomposition can be read as a signed account: reliability adds penalty, resolution subtracts a reward, and uncertainty is the empirical constant base-rate term. The next figure shows those terms for the two-bin example and checks that they add to the raw Brier score.
PythonIn [5]Expand
n_high, n_low = 5, 5
pred_high, pred_low = 0.9, 0.6
pos_high, pos_low = 4, 1
obs_high = pos_high / n_high
obs_low = pos_low / n_low
base_rate = (pos_high + pos_low) / (n_high + n_low)
rel_example = (
n_high * (pred_high - obs_high) ** 2 + n_low * (pred_low - obs_low) ** 2
) / (n_high + n_low)
res_example = (
n_high * (obs_high - base_rate) ** 2 + n_low * (obs_low - base_rate) ** 2
) / (n_high + n_low)
unc_example = base_rate * (1.0 - base_rate)
bs_raw_example = rel_example - res_example + unc_example
decomp_labels = ["Reliability", "Resolution", "Uncertainty", "Total Brier"]
decomp_values = [rel_example, -res_example, unc_example, bs_raw_example]VisualizationOut [6]Expand

Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!