Learning outcomes
By the end of this lesson, you will be able to:
- Explain why a probability or score can be converted into a class using different thresholds.
- Calculate TPR and FPR and interpret points on an ROC curve.
- Explain ROC-AUC and recognize its interpretation limits.
- Connect Precision and Recall to the Precision–Recall curve.
- Compare ROC-AUC and PR-AUC while accounting for positive-class prevalence and error costs.
1. From one operating point to a range of thresholds
In lessons 1.5.2 and 1.5.3, we used a confusion matrix and metrics derived from it. A binary classifier typically first produces a score or probability for the positive class. A threshold then converts that score into a class label.
For example, a model estimates the probability of equipment failure. At a threshold of 0.50, a score of 0.72 becomes a positive prediction, while 0.31 becomes a negative prediction. But 0.50 is not a natural law: a task may call for 0.30, 0.70, or another value.
Each threshold creates its own confusion matrix: TP, FP, TN, and FN change, so do Precision, Recall, F1, and other metrics from the previous lesson. Rather than inspecting one point, ROC and Precision–Recall curves show a family of points across thresholds.
2. The ROC curve: detection rate versus false-alarm rate
ROC stands for Receiver Operating Characteristic. At each threshold, calculate two quantities: True Positive Rate (TPR) and False Positive Rate (FPR). TPR is the same as Recall: the fraction of actual positives detected. FPR is the fraction of actual negatives incorrectly predicted as positive.
Symbols: TP means correctly detected positives; FN means missed positives. The denominator TP + FN contains all actual positive cases. A higher TPR means the model detects a larger share of them.
Symbols: FP means false positive predictions; TN means correctly recognized negatives. The denominator FP + TN contains all actual negative cases. FPR asks what fraction of negatives were incorrectly flagged.
The ROC plot places FPR on the horizontal axis and TPR on the vertical axis. Every threshold produces one point. At a very high threshold, almost no object is predicted positive, so both rates approach zero. At a very low threshold, almost everything is positive, so both approach one.
3. ROC-AUC: area under the ROC curve
AUC means Area Under the Curve. ROC-AUC compresses the ROC curve into one number. In the standard case it ranges from 0 to 1: values closer to 1 indicate that the model tends to rank positive objects above negative ones.
Here, FPR is the horizontal coordinate and TPR is the vertical coordinate of the ROC curve. The integral accumulates the curve's height across the full FPR range. In practice, the area is estimated from a finite set of points, for example with the trapezoidal rule.
There is also a probabilistic interpretation: ROC-AUC is the probability that a randomly selected positive object receives a higher score than a randomly selected negative object (ties usually receive half credit). It measures ranking, not the accuracy of probability estimates.
As rough reference points: 1.0 indicates perfect ranking; around 0.5 corresponds to random ordering; below 0.5 can indicate reversed ranking or an incorrectly defined positive class. The value does not guarantee an operating threshold with an acceptable number of false alerts.
4. The Precision–Recall curve: quality of positive predictions
ROC uses all actual negatives as the denominator of FPR. When negatives are very numerous, even many false alerts can produce a small FPR. As a result, an ROC curve may look optimistic when the positive class is rare.
The Precision–Recall (PR) curve plots Precision vertically against Recall horizontally as the threshold changes. It focuses on the positive class: how many actual positives are found, and how reliable the positive predictions are.
Each threshold creates a Precision/Recall pair. Lowering the threshold usually increases Recall because more positives are detected; false alerts may also increase, so Precision often falls. This is a trade-off, not a plotting defect.
5. PR-AUC and Average Precision are not always identical
PR-AUC usually refers to the area under a Precision–Recall curve. However, implementations and papers may aggregate curve points differently. In particular, Average Precision (AP) is a common step-wise summary that weights each increase in Recall by the corresponding Precision.
The points are ordered by threshold; Recallₙ is the current recall and Precisionₙ is the precision over that step. The sum uses positive increments in Recall. This is not necessarily equal to the trapezoidal area obtained by linearly joining the plotted points.
Therefore, a report should state exactly what was computed: Average Precision, trapezoidal PR-AUC, or a named library implementation. Do not compare values from different procedures as if they were identical.
Unlike ROC, a PR plot has no universal random diagonal. Its baseline Precision is the positive-class prevalence in the evaluated dataset. If only 2% of objects are positive, baseline Precision is about 0.02. PR metrics are therefore sensitive to the prevalence of the positive class.
6. Choosing between ROC-AUC and PR-AUC
ROC-AUC is useful for comparing ranking quality across both classes. It asks how often positives receive higher scores than negatives. PR-AUC / AP is more useful when the positive class is the main focus and both Precision and Recall matter, especially when positives are rare.
| Criterion | ROC-AUC | PR-AUC / AP |
|---|---|---|
| Axes | TPR versus FPR | Precision versus Recall |
| Focus | Separation of positive and negative objects | Quality of positive predictions |
| Random baseline | ROC-AUC around 0.5 | Precision approximately equals prevalence |
| Rare positive class | May look optimistic when TN is very large | Makes the Precision/Recall trade-off explicit |
| Does not provide | A selected threshold or probability calibration | A selected threshold; it depends on prevalence and the AP/AUC definition |
A practical workflow: define the positive class and use case; compare ROC-AUC and PR-AUC/AP using the same independent validation protocol; inspect the curves; select a threshold using task constraints; then freeze the decision and evaluate once on test. If a specific operating point matters, also report Precision, Recall, FPR, and the confusion matrix at the selected threshold.
Neither area replaces probability calibration, error-cost analysis, subgroup evaluation, or post-deployment monitoring. A high area is not proof of fairness, robustness, or causal validity.
7. Worked example: why ROC and PR tell different stories
Consider a quality-control system for 10,000 parts. One hundred are defective (1%) and 9,900 are sound. At one threshold, the model detects 80 defects, misses 20, raises false alerts for 198 sound parts, and correctly rejects 9,702. In confusion-matrix notation: TP = 80, FN = 20, FP = 198, TN = 9,702.
Then TPR = 80 / 100 = 0.80 (80%). FPR = 198 / 9,900 = 0.02 (2%). Precision = 80 / (80 + 198) ≈ 0.288 (28.8%). Recall = 80%. The ROC point is (0.02, 0.80), while the PR point is (0.80, 0.288).
The false-alert rate among sound parts is low at 2%, but there are 278 positive alerts and only 80 are actual defects. Precision is therefore about 28.8%. There is no contradiction: FPR uses all negatives (9,900) as its denominator, while Precision uses all positive predictions (278).
In practice, ROC helps assess ranking across both classes; PR more directly shows how many useful alerts a team receives at a required Recall. For rare defects, inspect the PR curve and the absolute alert count, not only FPR.
8. Limitations, common mistakes, and a sound evaluation protocol
- ROC-AUC is not Accuracy. AUC evaluates ranking across thresholds; Accuracy counts correct labels at one chosen threshold.
- High ROC-AUC does not guarantee high Precision. With rare positives, even a small FPR can create many false alerts.
- PR-AUC depends on prevalence. When comparing datasets with different positive rates, report prevalence and the data protocol.
- AP and trapezoidal PR-AUC can differ. Name the calculation method and implementation.
- Areas do not choose an operating threshold. Tune the threshold on validation, never repeatedly on test.
- Check score direction. Ensure higher scores mean stronger evidence for the positive class; otherwise ranking may be reversed.
- Use independent observations. Duplicates, temporal leakage, and dependent groups can invalidate evaluation.
Practice exercise
A quality-control system evaluates 10,000 parts: 100 defective and 9,900 sound. At a chosen threshold, the model produces TP = 80, FN = 20, FP = 198, and TN = 9,702.
- Calculate TPR, FPR, Precision, and Recall.
- Write the corresponding points on the ROC and PR curves.
- Explain why FPR = 2% does not mean Precision is 98%.
- Which plot matters most if every alert requires an expensive manual review? Explain.
- Which dataset should be used to select the threshold, and when should test be used?
Expected check: TPR = Recall = 80%; FPR = 2%; Precision ≈ 28.8%; ROC point (0.02, 0.80); PR point (0.80, 0.288). Precision and the PR curve, together with the absolute alert count, are especially relevant for costly manual reviews. Select the threshold on validation and reserve test for final evaluation.
Sources and further reading
- scikit-learn — ROC metrics. ROC curves, ROC-AUC definitions, and implementation details.
- scikit-learn — Precision, Recall, F-measure and Precision-Recall metrics. PR curves, Average Precision, and calculation details.
- Saito, T. & Rehmsmeier, M. (2015). The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets. PLOS ONE, 10(3).
Key terms
Knowledge check
Choose one answer for each question. Feedback appears after you check your answer.
Question 1
Which quantities are plotted on the ROC axes?
Question 2
What usually happens when the classification threshold is lowered?
Question 3
How should ROC-AUC = 0.5 be interpreted?
Question 4
What does FPR measure?
Question 5
Why is a PR curve especially useful for a rare positive class?
Question 6
How can Average Precision differ from trapezoidal PR-AUC?
Question 7
Which dataset should be used to select the operating threshold?