Sub topic 6
Reading a ROC curve: the diagonal, the corner, and trade-offs
This chapter assumes you can already build a ROC curve by sweeping a threshold, and that you know TPR (true positive rate) and FPR (false positive rate). Here you learn to read the finished curve and see what it says about a classifier.
Axes and endpoints
A ROC curve plots FPR on the x-axis against TPR on the y-axis. Each point is one threshold. Reading from the lower left to the upper right means lowering the threshold.
- (0, 0): the threshold is so high that nothing is predicted positive. No true positives and no false positives.
- (1, 1): the threshold is so low that everything is predicted positive. Every positive is caught, and every negative is a false alarm.
Every ROC curve runs between these two points. Only the path between them differs from model to model.
The diagonal: no skill
The line from (0, 0) to (1, 1) is where TPR equals FPR. A classifier whose scores carry no information about the label lands here. Raising the fraction of positives you catch raises the fraction of negatives you flag by the same amount.
A curve that sits mostly above the diagonal means the model ranks positives higher than negatives. A curve below the diagonal means the scores are inverted. Using the opposite decision rule (predict positive when the score is below the threshold) reflects each point through the center (0.5, 0.5), which turns a bad curve into a good one. Check for a label or sign mix-up before blaming the model.
The corner: perfect separation
The top-left corner (0, 1) means every positive is caught and no negative is flagged. A curve that rises straight up the left edge and then runs along the top has a threshold that separates the classes perfectly. The closer a curve hugs that corner, the better the ranking.
Reading the shape
import numpy as np
from sklearn.metrics import roc_curve
y_true = np.array([0, 0, 1, 1])
y_score = np.array([0.1, 0.4, 0.35, 0.8])
fpr, tpr, _ = roc_curve(y_true, y_score)
for x, y in zip(fpr, tpr):
print(f"FPR={x:.2f} TPR={y:.2f}")The output is the staircase (0, 0), (0, 0.5), (0.5, 0.5), (0.5, 1), (1, 1). On a finite sample the curve moves in steps:
- A vertical step means the next score down belongs to a positive example. TPR rises and FPR stays put.
- A horizontal step means the next score down belongs to a negative example. FPR rises and TPR stays put.
The point (0.5, 0.5) here lies on the diagonal. At that threshold the model is no better than chance, even though the full curve is above the line overall.
Trade-offs along the curve
Moving up and to the right buys more recall at the cost of more false alarms. The slope tells you the price. A steep section means each extra false positive brings a lot of new true positives. A flat section means you are mostly adding false alarms. Slope is not constant, so the best trade-off depends on where you stop.
| Region | TPR vs FPR | Meaning |
|---|---|---|
| Top-left corner | TPR near 1, FPR near 0 | Near-perfect separation |
| Above the diagonal | TPR > FPR | Useful ranking |
| On the diagonal | TPR = FPR | No information |
| Below the diagonal | TPR < FPR | Inverted scores |
Common reading errors
- Judging a model from one point. A single point is one threshold. Compare curves at the FPR your application can tolerate.
- Assuming the highest curve everywhere wins. Two curves can cross, and then which is better depends on the operating range.
- Forgetting that the curve describes ranking, not calibration. Rescaling scores with a monotonic function leaves the curve unchanged.
Exercise
In the example above, the threshold 0.4 predicts positive for the scores 0.4 and 0.8. Compute TPR and FPR at that threshold and say where the point lies relative to the diagonal.
Show answer
Of the two positives (scores 0.35 and 0.8), only 0.8 is flagged, so TPR = 1/2 = 0.5. Of the two negatives (scores 0.1 and 0.4), only 0.4 is flagged, so FPR = 1/2 = 0.5. The point (0.5, 0.5) lies on the diagonal, so at this threshold the model performs like random guessing.