Learning outcomes

By the end of this lesson, you will be able to:

Key questionHow can we compare two classifiers before choosing an operating threshold? And why can the same model look convincing on an ROC plot but much less impressive on a Precision–Recall plot?

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.

Decision threshold — the boundary above which a model score is treated as a positive prediction. Lowering the threshold usually produces more positive alerts; raising it produces fewer.

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.

How a threshold changes classificationThe same set of model scores is split into negative and positive predictions by different thresholds; moving the threshold changes detected cases and false alerts.Model scoresThresholdBelow threshold → negative predictionAbove threshold → positive prediction
A threshold is a configurable decision boundary, not an immutable property of a model. Colors mark score regions, not ground-truth labels.

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.

True Positive Rate (TPR)TPR = TP / (TP + FN) = Recall

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.

False Positive Rate (FPR)FPR = FP / (FP + TN)

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.

An example ROC curveThe axes show FPR and TPR from zero to one. The diagonal represents random ranking; a curve above it indicates better separation.False Positive Rate (FPR)True Positive Rate (TPR)0110ROC modelRandom baseline
The closer the curve is to the upper-left corner, the higher the TPR at a given FPR. This is a conceptual illustration, not a measured dataset.
ROC curve — a plot of TPR against FPR as the classification threshold changes. It shows the trade-off between detecting positives and generating false alarms.

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.

ROC-AUC definitionROC-AUC = ∫₀¹ TPR(FPR) d(FPR)

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.

Important: A high ROC-AUC does not tell you which threshold to use. Select a threshold on validation data using error costs and operational constraints. Do not repeatedly tune it on the test set.

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.

PR-curve coordinatesx = Recall = TP / (TP + FN)y = Precision = TP / (TP + FP)

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.

An example Precision–Recall curveThe plot shows Precision vertically and Recall horizontally; a dashed horizontal line marks the baseline positive-class prevalence.RecallPrecisionPR curveClass prevalence baseline
The baseline Precision equals the positive-class prevalence. The curve's shape depends on the model and dataset.
Precision–Recall curve — a plot of Precision against Recall for different thresholds. It helps evaluate the reliability and coverage of positive predictions.

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.

Average Precision (AP)AP = Σₙ (Recallₙ − Recallₙ₋₁) × 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.

CriterionROC-AUCPR-AUC / AP
AxesTPR versus FPRPrecision versus Recall
FocusSeparation of positive and negative objectsQuality of positive predictions
Random baselineROC-AUC around 0.5Precision approximately equals prevalence
Rare positive classMay look optimistic when TN is very largeMakes the Precision/Recall trade-off explicit
Does not provideA selected threshold or probability calibrationA 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.
Takeaway: ROC-AUC and PR-AUC compare ranking across thresholds but answer different questions. ROC plots TPR against FPR; PR plots Precision against Recall. For rare positive classes, the PR curve is especially informative, and prevalence plus the AP/AUC calculation method must be reported.

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.

  1. Calculate TPR, FPR, Precision, and Recall.
  2. Write the corresponding points on the ROC and PR curves.
  3. Explain why FPR = 2% does not mean Precision is 98%.
  4. Which plot matters most if every alert requires an expensive manual review? Explain.
  5. 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

  1. scikit-learn — ROC metrics. ROC curves, ROC-AUC definitions, and implementation details.
  2. scikit-learn — Precision, Recall, F-measure and Precision-Recall metrics. PR curves, Average Precision, and calculation details.
  3. 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

Decision thresholdПорог классификацииThe score boundary used to turn a model score into a positive or negative prediction.
ROC curveReceiver Operating CharacteristicA plot of TPR against FPR as the classification threshold changes.
ROC-AUCArea Under the ROC CurveThe area under the ROC curve; it summarizes ranking quality between positive and negative objects.
Precision–Recall curvePR curveA plot of Precision against Recall across classification thresholds.
Average Precision (AP)Average PrecisionA step-wise summary of a PR curve; it is not always equal to trapezoidal PR-AUC.

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?