Precision–Recall AUC (PR-AUC)

A precision–recall curve plots precision against recall as the decision threshold sweeps across the scores. PR-AUC is the area under it, and it summarizes how well the model ranks positives while charging directly for the false positives that ranking produces.

Unlike ROC-AUC, neither axis involves true negatives. That single difference produces everything distinctive about the metric.

The baseline is the prevalence

A random ranking achieves a precision equal to the positive rate at every recall, so its PR-AUC is approximately \(\pi\), the prevalence. On a dataset with 1 percent positives, no-skill PR-AUC is 0.01, not 0.5.

This makes a bare PR-AUC uninterpretable. A value of 0.42 is excellent at \(\pi = 0.05\) and catastrophic at \(\pi = 0.60\), and the number alone does not say which. The same fact means PR-AUC cannot be compared across datasets with different class balance — including across a training set that was resampled and a production stream that was not.

import numpy as np
from sklearn.metrics import roc_auc_score, average_precision_score

rng = np.random.default_rng(17)
pos_scores = rng.normal(1.2, 1.0, 2000)
neg_pool = rng.normal(0.0, 1.0, 400000)

for n_neg in (2000, 20000, 200000, 400000):
    s = np.concatenate([pos_scores, neg_pool[:n_neg]])
    y = np.concatenate([np.ones(pos_scores.size), np.zeros(n_neg)])
    prevalence = pos_scores.size / y.size
    print(f"prevalence {prevalence:.4f}  ROC-AUC {roc_auc_score(y, s):.4f}  "
          f"PR-AUC {average_precision_score(y, s):.4f}  baseline {prevalence:.4f}  "
          f"lift {average_precision_score(y, s) / prevalence:.2f}x")
# prevalence 0.5000  ROC-AUC 0.7963  PR-AUC 0.7948  baseline 0.5000  lift 1.59x
# prevalence 0.0909  ROC-AUC 0.8005  PR-AUC 0.3488  baseline 0.0909  lift 3.84x
# prevalence 0.0099  ROC-AUC 0.8000  PR-AUC 0.0676  baseline 0.0099  lift 6.83x
# prevalence 0.0050  ROC-AUC 0.8005  PR-AUC 0.0373  baseline 0.0050  lift 7.49x

One model, one set of scores, and only the number of negatives changes. ROC-AUC stays between 0.7963 and 0.8005 across a hundredfold shift in prevalence. PR-AUC falls from 0.7948 to 0.0373.

The last column is the part usually left out. Measured against its own baseline the model improves — 1.59 times the no-skill value at balance, 7.49 times at a prevalence of 0.5 percent. The model has not got worse; finding needles in a larger haystack is genuinely harder, and PR-AUC reports the difficulty of the task along with the quality of the ranking. That is the point of the metric, not a defect, provided the prevalence travels with the number.

The mechanism is the identity relating a point on one curve to a point on the other:

\(\text{precision} = \dfrac{\pi \cdot \text{TPR}}{\pi \cdot \text{TPR} + (1-\pi) \cdot \text{FPR}}\)

The ROC point \((\text{FPR}, \text{TPR})\) is unchanged by prevalence; the PR point it maps to is not.

How the two curves are related

Davis and Goadrich establish that the relationship is tighter than the usual “use PR for imbalanced data” advice suggests. For a fixed dataset there is a one-to-one correspondence between a curve in ROC space and a curve in PR space wherever recall is non-zero, and consequently “a curve dominates in ROC space if and only if it dominates in PR space”. A model that is uniformly better on one plot is uniformly better on the other.

What does not carry over is the summary. They note that “algorithms that optimize the area under the ROC curve are not guaranteed to optimize the area under the PR curve” — the curves correspond, the areas under them weight different regions, and a model selected on one can lose on the other.

Which summary you are reporting

“PR-AUC” names two different computations, and library defaults differ.

ComputationWhat it does
average_precision_score\(\sum_n (R_n - R_{n-1})P_n\). A step-wise sum with no interpolation — see average precision
auc(recall, precision)Trapezoidal area, which interpolates linearly between the sampled points
Interpolated AP (PASCAL VOC)Takes the running maximum of precision to the right of each recall, producing an envelope. A third number again

The trapezoid is the one to be careful with. scikit-learn warns that it “uses linear interpolation and can be too optimistic”, and Davis and Goadrich give the reason: “in PR space it is incorrect to linearly interpolate between points”, because the straight line between two achievable PR points passes through territory the classifier cannot reach. AP is often described as an interpolation of the PR curve; it is the one that is not.

A related detail: PR curves are not monotone. Adding one more case to the predicted-positive set can raise or lower precision, so the raw curve is a sawtooth. scikit-learn returns it that way and does not smooth it before summing.

Using it

Like any ranking summary, PR-AUC is invariant to strictly increasing rescaling of the scores, so it says nothing about calibration. It is also high-variance when positives are few, which is exactly when people reach for it — a hundred positives gives a noisy estimate, and a bootstrap interval is worth the effort.

Operationally the curve is more useful than its area. Where the requirement is “precision at least 0.9”, read the recall off the curve at that precision and report the pair: on a dataset of 1,000 samples with 50 positives, selecting 14 cases including 13 positives gives 26 percent recall at about 93 percent precision, which is a statement an operations team can plan around in a way that “PR-AUC 0.42” is not.

Report the prevalence, the computation used, an interval, and for multiclass whether the averaging is micro — which pools decisions and follows the common classes — or macro, which weights every class equally. Saito and Rehmsmeier’s case for the PR view is that it gives “an accurate prediction of future classification performance” on imbalanced data; that holds only when the evaluation set carries the prevalence you will actually meet.

References


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.