Learning outcomes
After this lesson, you will be able to:
- Distinguish ranking from probability calibration.
- Explain a reliability diagram and calibration curve.
- Calculate the Brier score and interpret log loss.
- Recognize overconfidence and underconfidence.
- Choose Platt scaling or isotonic regression based on data volume.
- Build a leakage-safe calibration workflow.
1. Probability is not the same as a class label
A classifier often produces a score or probability first; a threshold then converts it into a class label. If the prediction is 0.73 and the threshold is 0.5, the case is labelled positive. The label does not tell us whether 0.73 is a reliable probability. Two models can rank cases in the same order and achieve similar ROC-AUC while outputting probabilities such as 0.2 / 0.8 versus 0.45 / 0.95. Ranking may be similarly useful, while the numerical probabilities differ substantially.
Calibration asks whether predicted probabilities match observed event frequencies. For a perfectly calibrated model, an event should occur in about 80% of cases assigned probability 0.8. This statement concerns sufficiently large groups of comparable predictions, not an individual case: the outcome of a single event remains uncertain.
Keep three properties separate. Discrimination or ranking asks whether true positives receive higher scores than negatives. Calibration asks whether the numbers match frequencies. Sharpness describes how concentrated predictions are near 0 or 1 rather than near the base rate. Sharp predictions are useful only when they are sufficiently calibrated.
For example, a failure-risk system reports 0.9. This does not promise failure for one device. But if only half of hundreds of comparable devices assigned a risk near 0.9 actually fail, the probabilities are systematically too high.
2. Reading a calibration curve
A reliability diagram checks calibration by grouping predictions into bins. For each bin, calculate the mean predicted probability and the observed fraction of positive outcomes. Plot the mean prediction on the horizontal axis and the observed frequency on the vertical axis.
The diagonal y = x represents perfect calibration. A point at (0.8, 0.8) means that the event occurred in 80% of cases in a group whose mean predicted probability was 0.8. A point below the diagonal indicates overconfidence: predicted probabilities exceed observed frequency. A point above it indicates underconfidence: observed frequency exceeds the prediction.
Mean predicted probability and observed frequency are compared per bin. Here n_b is the number of cases in bin b, acc(b) is its observed event fraction, and conf(b) is its mean predicted probability. Lower ECE indicates smaller average absolute bin mismatch, but the result depends on binning.
Do not judge calibration from one attractive plot. Check sample size, uncertainty in observed frequencies, and relevant subgroups such as region, customer type, period, or device class. Good overall calibration can hide serious errors in a small but important group.
3. Brier score: probabilistic prediction error
For a binary outcome, encode the observed value yᵢ as 1 when the event occurs and 0 otherwise. The predicted probability pᵢ lies between 0 and 1. The Brier score is the mean squared difference between probability and outcome. It is zero for perfect predictions; lower is better.
A prediction of 0.8 when the event occurs contributes (0.8 − 1)² = 0.04. The same prediction when the event does not occur contributes (0.8 − 0)² = 0.64. A confident wrong prediction is therefore penalized more heavily than a moderate miss. The Brier score is a proper scoring rule: in expectation, the honest probability minimizes the score.
Consider four predictions: 0.1, 0.2, 0.8, 0.9 and outcomes 0, 1, 1, 1. The Brier score is (0.01 + 0.64 + 0.04 + 0.01) / 4 = 0.175. The value depends on event prevalence and the dataset, so compare models on the same sample and task.
The Brier score is sensitive to both calibration and discrimination; it is not a pure calibration measure. Combine it with a reliability diagram, the base rate, and ranking metrics.
Here n is the number of cases, pᵢ is the predicted probability, and yᵢ is the observed outcome (0 or 1). Average the squared probability errors.
4. Log loss and the cost of a confident mistake
Log loss, also called logarithmic loss or binary cross-entropy, evaluates the probability assigned to the outcome that actually occurred. If y = 1, the relevant probability is p; if y = 0, it is 1 − p. The lower the probability assigned to the true outcome, the larger the penalty. A prediction of 0.99 for an event that does not occur receives a very large penalty.
Unlike the Brier score, log loss grows without an upper bound as the probability assigned to the true outcome approaches zero. It is therefore especially sensitive to confident errors. In practice, probabilities may be clipped by a small epsilon for numerical stability; this must not hide poor predictions.
Both Brier score and log loss are proper scoring rules: when calculated correctly, the expected score is optimized by the true probability. Their values still depend on event prevalence, class separation, and the evaluation sample. Do not declare one model better using numbers from different test sets.
When probabilities drive decisions—reserves, inspection priorities, or risk estimates—a numerical probability error may matter more than ranking alone. Choose metrics based on the consequences of use.
pᵢ is the predicted event probability, yᵢ is the observed 0/1 outcome, and ln is the natural logarithm. The formula uses the probability of the outcome that occurred.
5. Calibration methods: Platt scaling and isotonic regression
Calibration is an additional transformation of an already trained classifier's outputs. The base model first produces a score or probability; a calibrator then transforms it into a more reliable probability. This does not automatically fix bad features, distribution shift, or poor ranking.
Platt scaling fits a logistic transformation of the original score. It is compact and often more stable with smaller calibration samples, but assumes a relatively simple relationship. For a binary task, it can be written as sigmoid(a·s + b), where s is the original score and a and b are fitted using separate calibration data.
Isotonic regression fits a monotonic, piecewise-constant transformation. It is more flexible and can correct nonlinear distortions, but requires more data. On a small sample it can fit noise and perform worse on new cases. Compare methods on independent data, not by how attractive the fitted curve looks.
Modern neural networks also use temperature scaling: logits are divided by a positive temperature T before softmax. It changes the confidence of the distribution and usually preserves class ranking. It is common for multiclass calibration, but does not guarantee that every type of error is fixed.
s is the model's original score; a and b are logistic-transformation parameters fitted on a separate calibration set.
6. A leakage-safe workflow: where to fit the calibrator
The main risk is leakage. If the calibrator is fitted on the same cases used to train the base model, its predictions are too optimistic because the model has already seen their labels. Do not select the method or its parameters using the final test set either.
A simple safe protocol is to split data into train, validation/calibration, and test. Train the base model only on train. Generate predictions on the calibration set, which was not used to fit the model. Fit the calibrator using those predictions and known outcomes. Freeze the full pipeline, then evaluate it once on test.
When data are scarce, use out-of-fold predictions: for each case, train the base model without that case and save the prediction from the model that did not see it. These predictions can train the calibrator. All preprocessing, feature selection, and resampling must stay inside training folds. The nested evaluation principle from lesson 1.5.6 helps assess the full tuning process without optimistic bias.
After deployment, monitor calibration over time and across subgroups. Changes in event prevalence, user behaviour, or data collection can break the match between probabilities and reality. Recalibration requires newly labelled data and another independent evaluation.
7. Limitations and common mistakes
Small samples make bin frequencies unstable. A calibration curve is not an exact law: show sample counts and, when data allow, uncertainty intervals or bootstrap estimates.
One overall curve can hide subgroup miscalibration: a model may overestimate risk in one group and underestimate it in another. Analyse groups that matter for the application and fairness, but do not split data so finely that each group contains too few events.
Calibration does not automatically improve ROC-AUC or guarantee a better decision threshold. A monotonic transformation usually preserves ranking while changing the numerical interpretation of probabilities. Choose the decision threshold separately, based on error costs and operational constraints.
Common mistakes include treating 0.8 as a promise about one case; evaluating a calibrator on its own training data; using test to choose a method; comparing Brier scores from different samples; ignoring the base rate; drawing conclusions from bins with very few cases; and forgetting to recheck after data drift.
8. Summary: probabilities must be testable
Calibration complements ranking metrics. ROC-AUC asks how well a model orders cases; a calibration curve checks whether predicted probabilities match observed frequencies; Brier score and log loss assess probabilistic predictions with different penalties.
The method depends on sample size and the shape of the distortion: Platt scaling is compact, isotonic regression is flexible but more data-hungry, and temperature scaling is often used for neural-network logits. Every calibrator must be fitted on data not used to train the base model, while the final test set remains untouched until evaluation.
The next step is to use calibrated probabilities in an actual decision: choose thresholds based on error costs, resource limits, and risk requirements. A probability is useful not because it looks convincing, but because its reliability has been tested on appropriate data.
Practical exercise
Eight cases received predictions 0.1, 0.2, 0.2, 0.3, 0.7, 0.8, 0.8, 0.9. Observed outcomes: 0, 0, 1, 0, 1, 1, 0, 1.
Split predictions into two groups: below 0.5 and at least 0.5. For each group, calculate the mean prediction and observed event fraction. Then calculate the Brier score across all eight cases.
Takeaways and next step
- ROC-AUC describes ranking; calibration describes agreement between probabilities and frequencies.
- Brier score and log loss evaluate probabilistic predictions but do not replace a reliability diagram.
- Fit a calibrator on independent or out-of-fold predictions; never tune it on test.
References
- scikit-learn — Probability calibration — Reliability diagrams and calibration methods.
- Niculescu-Mizil & Caruana (2005) — Predicting Good Probabilities with Supervised Learning — A study of calibrated probabilistic predictions.
- Guo et al. (2017) — On Calibration of Modern Neural Networks — Temperature scaling and neural-network calibration.
Key terms
Agreement between predicted probability and observed event frequency.
A plot of mean predicted probability against observed frequency in bins.
Mean squared error of probabilistic predictions for a binary outcome.
A penalty for assigning low probability to the outcome that occurred.
A flexible monotonic transformation from scores to calibrated probabilities.
Knowledge check
Choose one answer for each question. Explanations appear after checking.
Question 1
What does calibration evaluate?
Question 2
What does a point below the diagonal in a reliability diagram indicate?
Question 3
How should the Brier score be interpreted?
Question 4
Why does log loss strongly penalize a confident mistake?
Question 5
Which data should be used to fit a calibrator?
Question 6
Which statement about isotonic regression is correct?