Introduction: Going Beyond Binary
Accuracy, precision, recall (covered in Evaluation metrics) evaluate a binary decision (0 or 1) taken at a fixed threshold, typically 0.5. If the model's score exceeds 0.5, you predict "positive", otherwise "negative".
But your model doesn't just produce 0 or 1. It produces a continuous probability between 0 and 1. A patient with a score of 0.51 and another with 0.99 are both "positive" at the 0.5 threshold, but the model's confidence is radically different. Advanced metrics exploit this richness of information. They evaluate the quality of the probabilities themselves, not just the final decision.
Why is this crucial? Because the choice of threshold is arbitrary. And because in production, you often want to use probabilities directly (sorting cases by urgency, calibrating an alert system, etc.) rather than making a crude binary cutoff.
The Confusion Matrix: Seeing the Structure of Errors
The confusion matrix is the basic tool for visualizing how a model makes mistakes. It crosses the true classes (rows) with the predictions (columns).
For 2 classes (spam/not spam), it's a 2x2 matrix with our four friends: TP, FP, TN, FN.
For K classes, it's a KxK matrix. The diagonal shows correct predictions. Everything off-diagonal represents errors, and the position tells you exactly what confusion the model is making.
Rows are the true classes, columns are the predictions. In handwritten digit recognition, you often see that 4 is confused with 9, and 3 with 8 (visually similar). The matrix shows you these patterns of systematic errors, which no scalar metric can do. It's often the first tool to look at before choosing your metrics.
Useful derived metrics:
- Specificity : among all genuinely negative cases, what fraction does the model identify correctly? It is recall, but on the negative side.
- False Positive Rate (FPR) : the proportion of negative cases wrongly labelled positive. This is the false-alarm rate, and it is the horizontal axis of the ROC curve below.
The ROC Curve: Seeing the Entire Trade-off at Once
The ROC curve (Receiver Operating Characteristic) is a powerful tool that shows your model's performance at all possible thresholds simultaneously. It plots recall (also called the True Positive Rate (TPR)) on the vertical axis against the False Positive Rate (FPR) on the horizontal axis, sliding the decision threshold from 1 down to 0.
How to build it intuitively:
- Threshold = 1: the model never predicts "positive" (too demanding). TPR = 0, FPR = 0. This is the point (0, 0) at the bottom left.
- Threshold = 0: the model always predicts "positive" (no requirements). TPR = 1, FPR = 1. This is the point (1, 1) at the top right.
- By progressively lowering the threshold from 1 to 0, you trace the complete curve.
- Perfect model: the curve passes through the corner (0, 1), perfect recall with zero false positives. That's the dream.
- Random model: the diagonal from (0, 0) to (1, 1). The model does no better than chance.
The faster the curve "rises" toward the upper left corner, the better the model. It means you can achieve good recall while keeping a low false positive rate. If the curve hugs the diagonal, the model is random. If it goes below the diagonal, the model is worse than random: flip your predictions and you'll have a good model.
AUC: Summarizing the ROC in a Single Number
The AUC (Area Under the Curve) is, as the name says, the surface lying under the ROC curve. Since the curve is drawn inside a unit square, that area is a number between 0 and 1, summarizing in one figure how well the model separates the two classes.
- AUC = 1.0: perfect model. There exists a threshold that perfectly separates the classes.
- AUC = 0.5: random model. No better than flipping a coin.
- AUC = 0.0: inverted model. It systematically gets it wrong (flip your predictions and you get AUC = 1.0).
Probabilistic interpretation (very elegant): AUC represents the probability that a randomly chosen positive example receives a higher score than a randomly chosen negative example. An AUC of 0.9 means that in 90% of cases, a true positive will be ranked before a true negative. It is a concrete way to think about the quality of the ranking the model produces: its ability to put the right cases first.
Advantages of AUC:
- Threshold-independent: it evaluates the quality of the ranking, not of a decision taken at an arbitrary cut-off
- Relatively robust to imbalanced classes
- Makes it easy to compare models against each other
Important limitation: AUC gives equal weight to all regions of the graph. But in practice, an FPR of 0.8 (80% false alarms) is never acceptable. You only care about the left part of the curve (low FPR). AUC can therefore mask important differences in the region that actually matters.
Precision-Recall Curve: For Rare Classes
When a class is very rare (bank fraud: 0.1% of transactions, rare diseases), the ROC curve can be misleading. Why? Because the number of true negatives is so enormous that even many false positives barely move the FPR. The ROC curve looks excellent while the model is producing tons of false alerts.
The Precision-Recall curve is designed for these situations. It plots precision (Y-axis) against recall (X-axis) by varying the threshold.
The AUC-PR summarizes this curve. Key difference: a random model has an AUC-PR equal to the proportion of positives in the data (for example 0.001 if 0.1% fraud), and not 0.5 as with ROC. This makes it much more discriminating and informative for very rare classes.
Balanced classes (50/50 or close)? The ROC curve and standard AUC work well. Very rare class and you want to detect it (fraud, rare disease)? Use the Precision-Recall curve and AUC-PR. It's the only way to get an honest view of your performance.
Calibration: Are Your Probabilities Real?
Your model produces a score between 0 and 1, which we naturally interpret as a "probability of being positive". But is it really a reliable probability?
A model is well calibrated if when it says "80% chance of being positive", then among all cases where it gives a score around 0.8, exactly 80% are actually positive. The probabilities faithfully reflect reality.
Concrete example:
- Your model gives a score of 0.8 for 100 patients
- 80 are actually sick -> model is well calibrated at this confidence level
- Only 50 are sick -> model is overconfident (it says 80% but it's actually 50%)
- 95 are sick -> model is underconfident (it says 80% but it's actually 95%)
Why is calibration important? Imagine a doctor using your model: "the patient has a 90% risk of cancer". If the model is poorly calibrated and 90% actually means 40%, the medical decisions made will be absurd. In production, probabilities guide human decisions. If they lie, so do the decisions.
This is a well-documented phenomenon: deep networks tend to produce extreme scores (close to 0 or 1) even when the actual uncertainty is high. They predict "99% sure" but are only right 85% of the time. The reference paper on this, Guo and co-authors in 2017, measures the defect across modern networks and identifies among the aggravating factors depth, prolonged training, and (counter-intuitively) the presence of BatchNorm. Checking and correcting calibration is therefore essential before any deployment.
Reliability Diagram: Visualizing Calibration
To concretely see if your model is well calibrated, you build a reliability diagram. You group predictions by confidence levels (0-0.1, 0.1-0.2, ..., 0.9-1.0) and plot the true positivity rate for each group against the group's average confidence.
A perfectly calibrated model gives a diagonal line: confidence of 0.3 -> 30% true positives, confidence of 0.7 -> 70% true positives, etc.
If the points are above the diagonal, the model is underconfident (reality is better than what it thinks). If the points are below, the model is overconfident (it promises more than it delivers). This is the most common case with neural networks.
Brier Score: Calibration in a Single Number
The Brier score condenses calibration quality into a single scalar value:
Symbol by symbol: is the number of examples; the probability the model announced for example ; what actually happened, 1 if the case was positive and 0 otherwise; the square and the play the same role as in MSE.
In one sentence: for each case, measure the gap between the announced probability and what happened, square it, and average. Announcing 0.9 for a case that occurs costs ; announcing 0.9 for a case that does not costs .
It's essentially the MSE (Mean Squared Error) applied to probabilities: you measure the gap between the predicted probability and the actual outcome (0 or 1) for each example. The lower the Brier score, the better. A score of 0 = perfect calibration. The Brier score captures both discrimination (does the model separate the classes well?) and calibration (are the probabilities correct?).
The Brier score belongs to the family of proper scoring rules: the best average score is obtained by stating one's true belief. That makes it a good candidate for training a model to be calibrated, the stated goal of Jev's RLCD method.
Post-hoc Recalibration: Fixing Without Retraining
Good news: if your model is poorly calibrated, you can fix it after the fact, without touching the model itself. You keep its raw predictions and learn a transformation that adjusts the probabilities.
Temperature scaling
The simplest method, and often enough. You introduce a single parameter , called the temperature by analogy with statistical physics, where a higher temperature spreads a distribution out:
Two words worth pinning down. Logits are the raw scores the model emits before any conversion: arbitrary numbers on no fixed scale. Softmax is the function turning those raw scores into probabilities: it makes them all positive and forces their sum to be exactly 1.
In one sentence: divide every raw score by the same number before converting them into probabilities. Dividing by brings the scores closer together, so the distribution flattens: a 0.99 comes down toward 0.85 and overconfidence drops. changes nothing. spreads the scores apart and sharpens the probabilities, which helps when the model is instead too timid.
You optimize T on a separate validation set. A single parameter to learn, so virtually no risk of overfitting. This is the recommended default method.
Platt scaling
You learn a sigmoid transformation between the logit and the true class: , where is the sigmoid (the S-shaped curve squashing any number into the range 0 to 1) a scale factor and an offset. Two parameters instead of just one, so more flexibility than temperature alone. Useful when the relationship between the logit and the true probability isn't simply a matter of scale.
Isotonic regression
A so-called non-parametric approach, because no shape is imposed in advance. You simply learn a monotonic function (one that never comes back down: a higher score always yields an at-least-as-high probability) mapping raw scores to calibrated probabilities. More powerful, but it needs more validation data to avoid overfitting: an unconstrained function has far more room to trace the noise.
Summary of Tools
| Tool | What it measures | When to use it |
|---|---|---|
| Confusion matrix | Error patterns by class | Always, first |
| ROC curve / AUC | Overall discrimination | Balanced classes |
| PR curve / AUC-PR | Discrimination on rare class | Imbalanced classes |
| Reliability diagram | Probability quality | When probabilities guide decisions (healthcare, finance) |
| Brier score | Calibration + discrimination | A single number for probability quality |
Complete Evaluation: The Checklist
For a truly rigorous evaluation of a classification model, follow these steps in order:
- Confusion matrix: visually understand the structure of errors. Which classes are confused? Is there a pattern?
- ROC or PR curve: evaluate performance at different thresholds, not just 0.5. Identify the optimal threshold for your use case.
- Calibration: verify that probabilities are reliable, especially if they guide human decisions.
- Single numbers (AUC, F1, Brier): to compare models objectively and decide which to keep.
Graphs (matrix, curves) let you understand the real strengths and weaknesses of the model. Scalars (AUC, F1) let you compare objectively. Both are necessary.
Why This Matters
A good evaluation forces you to go beyond appearances. An AUC of 0.95 looks excellent. But if your model is massively overconfident, the probabilities it produces are unusable in production. An F1 of 0.90 is impressive, but if the PR (Precision-Recall) curve shows that performance collapses on the rarest cases (the ones that matter most) you have a problem. Evaluate properly, with the right tools, and you'll avoid nasty surprises in production.
1. What does an AUC of 0.9 concretely mean?
2. For bank fraud detection (0.1% of transactions), why can the ROC curve be misleading?
3. Your model announces a score of 0.8 for 100 patients; only 50 are actually sick. Diagnosis?
4. How does temperature scaling fix an overconfident model?
5. Why start an evaluation with the confusion matrix rather than with a global score?