Simple Algorithm
Machine Learning · Convergence · 26 min

ROC, AUC & Precision–Recall in Depth

What AUC really measures, and when PR curves tell the truth.

The area under the ROC curve is the most reported number in classification and one of the most misread. This lesson proves what it measures, a ranking probability, and how precisely a test set pins it down; turns costs and class priors into an optimal operating point with ROC geometry; shows why precision–recall space obeys different rules; and asks whether the AUC is a coherent measure of classification performance at all.

What you’ll learn

  • Prove that the AUC equals P(S+>S−)+12P(S+=S−)P(S^+>S^-)+\tfrac12P(S^+=S^-), identify the empirical AUC with the Mann–Whitney statistic, and evaluate it in the binormal model.
  • Estimate the standard error of an AUC, and know when DeLong's test and the partial AUC are the right tools.
  • Derive iso-cost lines, show that the ROC slope is a likelihood ratio, and find the optimal operating point on the ROC convex hull.
  • State and prove the correspondence and dominance theorems linking ROC and PR curves, interpolate correctly in PR space, and explain the prevalence baseline of the PR curve.
  • Explain Hand's critique of the AUC, the coherent reinterpretation that answered it, and the current debate over AUROC versus AUPRC.

AUC is a ranking probability

DerivationProof (continuous scores)
  1. AUC=∫01TPR du=∫+∞−∞(1−F+(t)) (−f−(t)) dt=∫−∞∞P(S+>t) f−(t) dt\mathrm{AUC}=\int_0^1\mathrm{TPR}\,du=\int_{+\infty}^{-\infty}\big(1-F_+(t)\big)\,\big(-f_-(t)\big)\,dt=\int_{-\infty}^{\infty}P(S^+>t)\,f_-(t)\,dt

    Parametrize the curve by the threshold. As tt runs from +∞+\infty down to −∞-\infty, u=FPR(t)u=\mathrm{FPR}(t) runs from 0 to 1 with du=−f−(t) dtdu=-f_-(t)\,dt:

  2. ∫−∞∞P(S+>t∣S−=t) f−(t) dt=P(S+>S−)\int_{-\infty}^{\infty}P(S^+>t\mid S^-=t)\,f_-(t)\,dt=P(S^+>S^-)

    The last integral conditions on the negative's score S−=tS^-=t and averages over it. By independence it is exactly the probability that the positive scores higher:

  3. AUC^=Un+n−,U=R+−n+(n++1)2\widehat{\mathrm{AUC}}=\frac{U}{n_+n_-},\qquad U=R_+-\frac{n_+(n_++1)}{2}

    Empirical version. Sort the nn scores and walk down the list: each positive moves the ROC staircase up by 1/n+1/n_+, each negative right by 1/n−1/n_-. A negative's horizontal step sits at height (positives ranked above it)/n+/n_+, so the area counts the correctly ordered pairs. With R+R_+ the sum of the positives' ranks (rank 1 = lowest score), that count is the Mann–Whitney UU; a tie moves diagonally and contributes a triangle, half a pair:

The binormal model. If S−∼N(μ−,σ−2)S^-\sim\mathcal N(\mu_-,\sigma_-^2) and S+∼N(μ+,σ+2)S^+\sim\mathcal N(\mu_+,\sigma_+^2) independently, then S+−S−∼N(μ+−μ−, σ+2+σ−2)S^+-S^-\sim\mathcal N(\mu_+-\mu_-,\ \sigma_+^2+\sigma_-^2), so AUC=Φ((μ+−μ−)/σ+2+σ−2)\mathrm{AUC}=\Phi\big((\mu_+-\mu_-)/\sqrt{\sigma_+^2+\sigma_-^2}\big). With unit variances and a separation of dd standard deviations, AUC=Φ(d/2)\mathrm{AUC}=\Phi(d/\sqrt2).

Predict before you look

Negatives score N(0,1)\mathcal N(0,1) and positives N(1.5,1)\mathcal N(1.5,1), as in the widget of the next step. What is the AUC?

Show the answer

0.856

AUC=Φ(1.5/2)=Φ(1.061)≈0.856\mathrm{AUC}=\Phi(1.5/\sqrt2)=\Phi(1.061)\approx0.856. A separation of one standard deviation would give Φ(0.707)≈0.760\Phi(0.707)\approx0.760, and two would give Φ(1.414)≈0.921\Phi(1.414)\approx0.921: the AUC saturates quickly as the classes pull apart.

How precise is an estimated AUC? A^=U/(n+n−)\hat A=U/(n_+n_-) is unbiased, and its variance follows from U-statistic theory. Hanley & McNeil (1982) approximated it in closed form, with Q1Q_1 the probability that two random positives both outrank one random negative and Q2Q_2 that one positive outranks two negatives, evaluated in an exponential model of the scores as Q1=A/(2−A)Q_1=A/(2-A) and Q2=2A2/(1+A)Q_2=2A^2/(1+A):

SE2(A^)=A(1−A)+(n+−1)(Q1−A2)+(n−−1)(Q2−A2)n+n− ≈ Q1−A2n−+Q2−A2n+.\mathrm{SE}^2(\hat A)=\frac{A(1-A)+(n_+-1)(Q_1-A^2)+(n_--1)(Q_2-A^2)}{n_+n_-}\ \approx\ \frac{Q_1-A^2}{n_-}+\frac{Q_2-A^2}{n_+}.

Each class's count divides its own term, so the rarer class sets the precision. How the two terms compare depends on the score model. In the exponential model at A=0.85A=0.85, Q2−A2Q_2-A^2 is three and a half times Q1−A2Q_1-A^2, so 100 positives and 900 negatives give SE≈0.025\mathrm{SE}\approx0.025 while 900 positives and 100 negatives give 0.015. For binormal scores with equal variances the two terms are equal, and the exact variance gives a standard deviation of about 0.020 for both mixes of counts (a simulation agrees). DeLong, DeLong & Clarke-Pearson (1988) estimate the variance nonparametrically, from each case's placement among the other class, and their test compares two AUCs measured on the same cases, whose estimates are correlated.

ROC versus precision–recall, precisely

Fix a test set with n+n_+ positives and n−n_- negatives. An operating point is a pair of counts (TP,FP)(TP,FP), which ROC space shows as (FP/n−, TP/n+)(FP/n_-,\ TP/n_+) and precision–recall (PR) space as (TP/n+, TP/(TP+FP))\big(TP/n_+,\ TP/(TP+FP)\big). These are two coordinate systems for the same counts, which gives two theorems at once.

DerivationProof
  1. (FPR,TPR) ⟼ (TPR, n+TPRn+TPR+n−FPR)(\mathrm{FPR},\mathrm{TPR})\ \longmapsto\ \Big(\mathrm{TPR},\ \frac{n_+\mathrm{TPR}}{n_+\mathrm{TPR}+n_-\mathrm{FPR}}\Big)

    (i) With recall R=TP/n+>0R=TP/n_+>0, the PR point determines TP=Rn+TP=Rn_+ and, from precision PP, FP=TP(1−P)/PFP=TP(1-P)/P; conversely the ROC point determines both counts. So the map between the two pictures is a bijection:

  2. FPRA(r)≤FPRB(r)  ∀r⟺PA(r)≥PB(r)  ∀r\mathrm{FPR}_A(r)\le\mathrm{FPR}_B(r)\ \ \forall r\quad\Longleftrightarrow\quad P_A(r)\ge P_B(r)\ \ \forall r

    (ii) At a fixed recall, that is a fixed TPR, precision is strictly decreasing in FPR. Curve A dominates B in ROC space exactly when, at every TPR, A reaches it at an FPR no larger than B's, which is exactly when A's precision at every recall is at least B's:

  3. P(λ)=(1−λ)TPA+λTPB(1−λ)(TPA+FPA)+λ(TPB+FPB)P(\lambda)=\frac{(1-\lambda)TP_A+\lambda TP_B}{(1-\lambda)(TP_A+FP_A)+\lambda(TP_B+FP_B)}

    Interpolation. Between two achievable points (TPA,FPA)(TP_A,FP_A) and (TPB,FPB)(TP_B,FP_B), randomizing between the two classifiers with weight λ\lambda moves both counts linearly. In ROC space that is a straight segment. In PR space precision becomes a ratio of linear functions of recall, a hyperbola, so a straight line between PR points is not achievable. When precision falls from the first point to the second, as it usually does, the hyperbola bends below the line, and the line overstates the area:

The chance level differs. A classifier that flags each case with probability qq regardless of x\mathbf x expects TP=qn+TP=qn_+ and FP=qn−FP=qn_-: it lies on the ROC diagonal, but in PR space its precision is the prevalence π\pi at every recall. So chance always scores an AUC of 0.5 (the converse fails: a curve that crosses the diagonal can also enclose 0.5), while the chance value of the area under the PR curve is π\pi, which can be 0.01 or 0.5 (Saito & Rehmsmeier, 2015). A PR summary is only comparable across datasets with the same prevalence.

Check your understanding

A model scores AP = 0.80 on dataset X, where half the cases are positive, and AP = 0.40 on dataset Y, where 2% are. Which conclusion is justified?

  1. The model ranks far better on X than on Y
  2. None about relative quality from these numbers alone: the chance-level AP is 0.5 on X and 0.02 on Y
  3. The model is worse than chance on Y
  4. The ROC AUC must also be lower on Y
Show the answer

B. None about relative quality from these numbers alone: the chance-level AP is 0.5 on X and 0.02 on Y

AP's chance value is the prevalence. 0.80 is 1.6 times chance on X and 0.40 is 20 times chance on Y; neither ratio is a principled comparison either, because precision mixes the model's error rates with the base rate. To compare the model's ranking across the two datasets, look at ROC curves or at precision at matched prevalence.

Costs, iso-cost lines and the convex hull

With prevalence π\pi and error costs cFPc_{\mathrm{FP}}, cFNc_{\mathrm{FN}}, every point of ROC space has an expected cost per case, and its level sets are straight lines. ROC geometry thereby turns "which threshold?" into "which tangent?" (Provost & Fawcett, 2001).

DerivationIso-cost lines and the optimal threshold
  1. C=(1−π) cFP FPR+π cFN (1−TPR),TPR=m FPR+const,m=(1−π) cFPπ cFNC=(1-\pi)\,c_{\mathrm{FP}}\,\mathrm{FPR}+\pi\,c_{\mathrm{FN}}\,(1-\mathrm{TPR}),\qquad\mathrm{TPR}=m\,\mathrm{FPR}+\text{const},\quad m=\frac{(1-\pi)\,c_{\mathrm{FP}}}{\pi\,c_{\mathrm{FN}}}

    The expected cost of operating at (FPR,TPR)(\mathrm{FPR},\mathrm{TPR}) is linear in both coordinates, so equal-cost points lie on parallel lines of slope mm; cheaper lines lie further up and to the left:

  2. d TPRd FPR∣t=f+(t)f−(t)=m\frac{d\,\mathrm{TPR}}{d\,\mathrm{FPR}}\bigg|_t=\frac{f_+(t)}{f_-(t)}=m

    Slide a line of slope mm up-left until it last touches the curve. On a smooth curve the contact point has slope mm, and the slope at threshold tt is the likelihood ratio of the scores there, since d TPR/dt=−f+(t)d\,\mathrm{TPR}/dt=-f_+(t) and d FPR/dt=−f−(t)d\,\mathrm{FPR}/dt=-f_-(t):

  3. p1−p=cFPcFN⟺p⋆=cFPcFP+cFN\frac{p}{1-p}=\frac{c_{\mathrm{FP}}}{c_{\mathrm{FN}}}\quad\Longleftrightarrow\quad p^\star=\frac{c_{\mathrm{FP}}}{c_{\mathrm{FP}}+c_{\mathrm{FN}}}

    So the ROC curve is concave exactly when the likelihood ratio increases with the score. If the score is a calibrated probability p=P(y=1∣s)p=P(y=1\mid s), Bayes' rule gives f+/f−=p1−p⋅1−ππf_+/f_-=\frac{p}{1-p}\cdot\frac{1-\pi}{\pi}, the prior cancels, and the tangency condition becomes the familiar cost threshold:

  4. t⋆=ln⁡m+d2/2dt^\star=\frac{\ln m+d^2/2}{d}

    For binormal scores with unit variances, f+(t)/f−(t)=edt−d2/2f_+(t)/f_-(t)=e^{dt-d^2/2}, so the optimal threshold has a closed form:

In the widget (d=1.5d=1.5), π=0.1\pi=0.1 with cFN=9cFPc_{\mathrm{FN}}=9c_{\mathrm{FP}} gives m=1m=1 and t⋆=0.75t^\star=0.75, its starting threshold; so does π=0.05\pi=0.05 with cFN=19cFPc_{\mathrm{FN}}=19c_{\mathrm{FP}}. Only the product of the prior odds and the cost ratio matters, which is why a model trained at one prevalence can be re-aimed at another by moving the threshold alone.

Predict before you look

Plain accuracy charges both errors equally. With 30% positives, as in the widget's default, what is the slope mm of the iso-accuracy lines?

Show the answer

2.33

m=(1−π)/π=0.7/0.3≈2.33m=(1-\pi)/\pi=0.7/0.3\approx2.33. Then t⋆=(ln⁡2.33+1.125)/1.5≈1.31t^\star=(\ln2.33+1.125)/1.5\approx1.31, where TPR = 0.575 and FPR = 0.095: the widget's accuracy readout peaks there at 0.806, against 0.773 at the default threshold. Negatives outnumber positives, so maximizing accuracy means flagging conservatively.

What the AUC is not, and where the debate stands

Hand's critique. Suppose the classifier will be run at the cost-optimal threshold for a cost parameter that is uncertain, with some distribution over its values. Hand (2009) showed that the AUC is a linear function of the expected minimum misclassification loss, but under a cost distribution that depends on the classifier's own score distributions. Comparing two classifiers by AUC therefore judges them with two different beliefs about the costs, which he called fundamentally incoherent. His H measure uses one cost distribution for every classifier, a Beta(2, 2) by default.

A coherent reading. Flach, Hernández-Orallo & Ferri (2011) replied that the AUC is also linearly related to expected loss under a model-independent scheme: costs drawn uniformly, and the threshold set at a uniformly chosen data point rather than optimally. If thresholds will be set optimally, they argued, the area under the cost curve is the natural measure. The upshot is not that the AUC is wrong but that it answers a ranking question, and is a cost measure only under assumptions about how thresholds will be chosen.

Partial AUC. When only a region matters, say false-positive rates below f0f_0 for screening a large population, integrate there: pAUC(f0)=∫0f0TPR du\mathrm{pAUC}(f_0)=\int_0^{f_0}\mathrm{TPR}\,du. McClish (1989) rescaled it so that chance maps to 12\tfrac12 and perfection to 1, As=12[1+(pAUC−f02/2)/(f0−f02/2)]A_s=\tfrac12\big[1+(\mathrm{pAUC}-f_0^2/2)/(f_0-f_0^2/2)\big]. For the widget's scores, AUC = 0.856 overall, but over FPR≤0.1\mathrm{FPR}\le0.1 the standardized partial AUC is only 0.69: in the region a screening program would use, the ranking is much less impressive.

Check your understanding

Model A has AUC 0.90 and model B 0.88, but B has the higher true-positive rate at every false-positive rate below 0.05. A screening program can tolerate at most 2% false positives. Which model should it use?

  1. A, because its AUC is higher
  2. Either, since a 0.02 difference in AUC is negligible
  3. B, because it is better throughout the region where the program will operate
  4. Neither: crossing ROC curves mean neither is valid
Show the answer

C. B, because it is better throughout the region where the program will operate

The program will operate at an FPR of at most 0.02, and there B catches more positives. A's advantage lies at higher FPRs the program will never use. The partial AUC over [0,0.05][0,0.05], or simply TPR at FPR = 0.02 with a confidence interval, is the relevant comparison.

AUROC or AUPRC under imbalance? A widely repeated rule says to prefer the area under the PR curve when positives are rare. McDermott et al. (2024) traced the rule through the literature and argued that the AUPRC is not generally superior under class imbalance: it rewards fixing mistakes among the highest-scoring cases, and when subpopulations differ in prevalence it can favor improvements for the group with more positives, which can widen disparities between groups. Neither summary replaces asking how the model will be used: screening a whole population, reviewing the top of a list, or ranking within groups.

Key takeaways

  • AUC=P(S+>S−)+12P(S+=S−)\mathrm{AUC}=P(S^+>S^-)+\tfrac12P(S^+=S^-): the empirical AUC is the Mann–Whitney UU over n+n−n_+n_-, and in the binormal model it is Φ(Δμ/σ+2+σ−2)\Phi\big(\Delta\mu/\sqrt{\sigma_+^2+\sigma_-^2}\big).
  • The AUC's sampling error is driven by the rarer class; DeLong's method gives nonparametric variances and compares correlated AUCs measured on the same cases.
  • Iso-cost lines have slope (1−π)cFP/(πcFN)(1-\pi)c_{\mathrm{FP}}/(\pi c_{\mathrm{FN}}), the ROC slope at a threshold is the likelihood ratio there, and only points on the ROC convex hull can ever be optimal.
  • ROC and PR curves correspond one-to-one and share dominance, but PR space cannot be interpolated linearly and its chance level is the prevalence.
  • The AUC summarizes ranking, not cost: Hand showed it implicitly uses classifier-dependent cost distributions; read it beside the operating region you will use.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Negatives score N(0,1)\mathcal N(0,1) and positives N(2,1)\mathcal N(2,1). What is the AUC?

  1. Φ(2)≈0.977\Phi(2)\approx0.977
  2. Φ(1)≈0.841\Phi(1)\approx0.841
  3. Φ(2)≈0.921\Phi(\sqrt2)\approx0.921
  4. 0.5+2/10=0.70.5+2/10=0.7
Show the answer

C. Φ(2)≈0.921\Phi(\sqrt2)\approx0.921

S+−S−∼N(2,2)S^+-S^-\sim\mathcal N(2,2), so AUC=P(S+−S−>0)=Φ(2/2)=Φ(2)≈0.921\mathrm{AUC}=P(S^+-S^->0)=\Phi(2/\sqrt2)=\Phi(\sqrt2)\approx0.921.

Question 2

Positives are 20% of cases and a false negative costs twice as much as a false positive. What is the slope of the iso-cost lines in ROC space?

  1. 0.5
  2. 2
  3. 4
  4. 0.25
Show the answer

B. 2

m=(1−π) cFPπ cFN=0.8⋅10.2⋅2=2m=\dfrac{(1-\pi)\,c_{\mathrm{FP}}}{\pi\,c_{\mathrm{FN}}}=\dfrac{0.8\cdot1}{0.2\cdot2}=2. The optimal operating point is where the ROC curve's slope, the likelihood ratio f+(t)/f−(t)f_+(t)/f_-(t), equals 2.

Question 3

You have two classifiers' operating points and may randomize between them. Which statement is correct?

  1. Every point on the straight segment between them is achievable in PR space but not in ROC space
  2. Neither picture allows interpolation
  3. Both pictures allow straight-line interpolation
  4. Every point on the straight segment between them is achievable in ROC space; in PR space the achievable path is curved
Show the answer

D. Every point on the straight segment between them is achievable in ROC space; in PR space the achievable path is curved

Randomizing with weight λ\lambda makes TP and FP linear in λ\lambda. TPR and FPR are those counts divided by constants, so the ROC path is straight; precision is a ratio of two linear functions, so the PR path bends, and the straight PR segment overstates what is achievable.

Question 4

A classifier's ROC point lies strictly below the convex hull of the other available operating points. What follows?

  1. It is never the cheapest choice, whatever the costs and class priors
  2. It is optimal for exactly one cost ratio
  3. It is the best choice whenever positives are rare
  4. Nothing can be said without knowing the costs
Show the answer

A. It is never the cheapest choice, whatever the costs and class priors

For any slope mm of the iso-cost lines, the cheapest achievable point is where the highest line of that slope touches the hull, and a point strictly inside the hull always has a hull point (possibly a randomized mix) with lower expected cost. Such a classifier can be discarded without knowing the costs (Provost & Fawcett, 2001).

Further reading

  • J. A. Hanley & B. J. McNeil, "The meaning and use of the area under a receiver operating characteristic (ROC) curve," Radiology 143(1), 29–36 (1982).
  • F. Provost & T. Fawcett, "Robust classification for imprecise environments," Machine Learning 42(3), 203–231 (2001).
  • J. Davis & M. Goadrich, "The relationship between precision-recall and ROC curves," Proceedings of ICML (2006).
  • D. J. Hand, "Measuring classifier performance: a coherent alternative to the area under the ROC curve," Machine Learning 77, 103–123 (2009).
  • T. Fawcett, "An introduction to ROC analysis," Pattern Recognition Letters 27(8), 861–874 (2006).