Interactive guide

The metric that doesn't get fooled by rare classes

The ROC & AUC page used one fixed model and asked "what does it cost to be wrong?" This page asks a different question with the exact same slider and confusion matrix: what happens to that model's curve when the positive class becomes rare? ROC's answer: almost nothing. Precision-Recall's answer: everything.

Recall is TPR wearing a different name

Recall is exactly the ROC page's TPR: of everyone truly positive, how many did the model catch? Nothing new there. The difference is what it gets paired with. ROC pairs recall with FPR, whose denominator (FP + TN) is the entire negative class, however huge. Precision instead pairs it with FP directly against TP: of everyone the model flagged, how many were actually right?

That one denominator swap is the whole story. When negatives vastly outnumber positives, FPR can stay tiny (a small fraction of a huge number) while precision craters (the same false positives now swamp a small handful of true ones). ROC never notices; precision notices immediately.

F1 is the harmonic mean of precision and recall, one number that's low unless both are reasonably high. Sliding the threshold traces an entire Precision-Recall curve, the same way sliding it traced the ROC curve, and its own area (PR AUC) is what actually degrades when a class goes rare, which the Class Imbalance & Resampling page shows happening to accuracy too.

Same slider, new pairing

  1. 1

    Slide the threshold from 1 to 0

    Exactly as on the ROC page: every step recomputes the same TP/FP/FN/TN from the same scored examples.

  2. 2

    Plot precision against recall instead of TPR against FPR

    Same sweep, same underlying counts, a completely different picture once negatives dominate.

  3. 3

    Track F1 across every threshold

    One number balancing both; its peak marks the threshold that best trades one off against the other.

  4. 4

    Switch the population, not the model

    Same per-class score distributions, just fewer positives. Watch which curve moves and which one doesn't.

Below is the same kind of model as the ROC page: 200 labeled examples, scored once with a balanced 50/50 class split and once with the same classifier's scores resampled into a heavily imbalanced 10%/90% split. Toggle between them below.

Case 1 · Balanced classes

100 positive, 100 negative

A 50/50 split: the textbook case every metric was designed to handle gracefully.

ROC AUC
PR AUC
Predicted positive
Predicted negative
Actual positive
0 True Positive
0 False Negative
Actual negative
0 False Positive
0 True Negative
0.50
Precision
TPTP + FP
=
0 0
=
0%
Recall (TPR)
TPTP + FN
=
0 0
=
0%
F1 score
2 × P × RP + R
=
0%
False positive rate for comparison
FPFP + TN
=
0 0
=
0%
Precision-Recall curve PR AUC —

y = Precision = TP / (TP+FP) x = Recall = TP / (TP+FN)

1 0 1 Recall (x) Precision (y)

this model   baseline (positive rate)

F1 by threshold best F1 ≈ 0.00
1.0 0.5 0 F1 score (y) 0.00 0.50 1.00 Decision threshold (x)

F1 at threshold   best-F1 threshold

On the balanced dataset, ROC AUC (0.8373) and PR AUC (0.8323) tell nearly the same story. Switch to the imbalanced dataset and ROC AUC actually holds up (0.8658), while PR AUC collapses to 0.3942 and the best achievable F1 falls from 0.7768 to 0.4828. Same model, same threshold sweep, opposite verdicts, because only one of these curves' denominators actually contains the rare class.

The jargons

Everything here reuses the four counts from the ROC page's confusion matrix; only the pairing changes.

Precision

Of everything flagged positive, how much actually was. Falls fast when false positives start to outnumber a rare true class.

Recall = TPR

Of everything truly positive, how much got caught. Identical definition to the ROC page's TPR, just paired differently.

F1 score

The harmonic mean of precision and recall: 2PR/(P+R). Stays low unless both are simultaneously decent.

Precision-Recall (PR) curve

Precision plotted against recall across every threshold, the same sweep that produces the ROC curve, just a different pair of axes.

PR AUC Average Precision

Area under the PR curve. Unlike ROC AUC, its baseline (a useless classifier) equals the positive rate, not a flat 0.5.

Why PR over ROC on imbalanced data

FPR's denominator is the whole negative class, so it barely moves even with many false positives. Precision's denominator is TP+FP directly, so it reacts immediately.

A teaching tool: both scenarios reuse the exact same per-class score-generating distributions as each other and the same confusion-matrix machinery as the ROC & AUC page; only the number of positive and negative examples drawn from those distributions changes.