Skip to content
AI360Xpert
Beta
Core ML

Visual explainer

Precision-Recall Curve

Forty hits, ten false alarms and twenty misses give precision 0.80 and recall 0.667, and one curve shows every threshold between strict and lax.

Always saying no scores 99 percent and catches zero fraud.
Always saying no scores 99 percent and catches zero fraud.

In real-world machine learning systems, extreme class imbalance is the norm rather than the exception. Consider a fraud detection pipeline where only 11 in every 100100 transactions is malicious (1%1\% positive prevalence, P(Y=1)=0.01P(Y=1) = 0.01).

A trivial classifier that stubbornly predicts "clean" for every single transaction achieves an impressive nominal accuracy:

Accuracy=TP+TNTotal=0+99100=99.0%\text{Accuracy} = \frac{\text{TP} + \text{TN}}{\text{Total}} = \frac{0 + 99}{100} = 99.0\%

Accuracy applauds this model as 99%99\% optimal, even though it detects zero fraud (0%0\% capture rate) while malicious actors siphon off capital uncontested. When the positive class is rare and mission-critical, raw classification accuracy is actively deceitful.

Counts Become Rates

Forty hits and ten alarms make precision 0.80 while twenty misses make recall 0.667.
Forty hits and ten alarms make precision 0.80 while twenty misses make recall 0.667.

To measure performance without getting blinded by the vast majority of negative events, we partition predictions into a 2×22 \times 2 confusion contingency table: 4040 True Positives (TP\text{TP}), 1010 False Positives (FP\text{FP}), 2020 False Negatives (FN\text{FN}), and 3030 True Negatives (TN\text{TN}).

From these four raw counts, we derive two focused rates:

Precision=TPTP+FP=4040+10=4050=0.800(80.0%)\text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}} = \frac{40}{40 + 10} = \frac{40}{50} = 0.800 \quad (80.0\%)

Recall=TPTP+FN=4040+20=4060≈0.667(66.7%)\text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}} = \frac{40}{40 + 20} = \frac{40}{60} \approx 0.667 \quad (66.7\%)

Precision measures quality: when the model raises an alarm, how often is it right? Recall (or sensitivity) measures coverage: of all true positive events that occurred, what fraction did the model successfully intercept?

In contrast, global accuracy lumps all counts together into:

Accuracy=TP+TNTotal=40+30100=0.700(70.0%)\text{Accuracy} = \frac{\text{TP} + \text{TN}}{\text{Total}} = \frac{40 + 30}{100} = 0.700 \quad (70.0\%)

Accuracy masks the critical operational reality: 2020 out of 6060 real fraud events slipped past the perimeter completely undetected.

Sweep the Threshold

Strict gives 0.92 precision at 0.40 recall while lax gives 0.95 recall at 0.63 precision.
Strict gives 0.92 precision at 0.40 recall while lax gives 0.95 recall at 0.63 precision.

Probabilistic classifiers do not emit hard binary labels; they compute continuous posterior probabilities p=P(Y=1∣x)∈[0,1]p = P(Y=1 \mid \mathbf{x}) \in [0, 1]. Transforming continuous probabilities into discrete production actions requires choosing a decision threshold τ\tau:

y^={1if P(Y=1∣x)≥τ0otherwise\hat{y} = \begin{cases} 1 & \text{if } P(Y=1 \mid \mathbf{x}) \ge \tau \\ 0 & \text{otherwise} \end{cases}

Sweeping τ\tau across the interval [0,1][0, 1] traces the continuous Precision-Recall (PR) curve:

  • Strict Threshold (τ=0.80\tau = 0.80): Demands overwhelming evidence before raising an alert. Precision surges to 0.920.92 (only 8%8\% false alarms), but Recall plummets to 0.400.40 (missing 60%60\% of actual targets).
  • Balanced Threshold (τ=0.50\tau = 0.50): Reconciles precision and recall, yielding Precision=0.80\text{Precision} = 0.80 and Recall=0.667\text{Recall} = 0.667. The harmonic mean (F1F_1 score) reaches: F1=2⋅Precision⋅RecallPrecision+Recall=2⋅0.80⋅0.6670.80+0.667≈0.727F_1 = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}} = 2 \cdot \frac{0.80 \cdot 0.667}{0.80 + 0.667} \approx 0.727
  • Lax Threshold (τ=0.20\tau = 0.20): Casts an aggressive net. Recall peaks at 0.950.95 (intercepting 95%95\% of all incidents), but Precision degrades to 0.630.63, flooding analysts with false alarms.

ROC Brags, PR Tells

ROC area 0.92 boasts while PR area 0.71 tells the truth.
ROC area 0.92 boasts while PR area 0.71 tells the truth.

Receiver Operating Characteristic (ROC) curves plot the True Positive Rate against the False Positive Rate (FPR=FP/N\text{FPR} = \text{FP} / N). When evaluating heavily imbalanced datasets, ROC curves exhibit a dangerous structural distortion.

Suppose a population contains 100100 positives (P=100P = 100) and 9,9009,900 negatives (N=9,900N = 9,900). At a threshold producing 8080 true positives and 100100 false positives:

TPR=TPP=80100=0.800(80.0%)\text{TPR} = \frac{\text{TP}}{P} = \frac{80}{100} = 0.800 \quad (80.0\%)

FPR=FPN=1009,900≈0.0101(1.01%)\text{FPR} = \frac{\text{FP}}{N} = \frac{100}{9,900} \approx 0.0101 \quad (1.01\%)

Because the negative pool N=9,900N = 9,900 is massive, the denominator absorbs the 100100 false alarms with ease. The ROC curve records an exceptional operating coordinate of (0.0101,0.800)(0.0101, 0.800), driving the Area Under the ROC Curve (AUROC\text{AUROC}) to a flattering 0.920.92.

However, looking at the actual precision reveals an operational disaster:

Precision=TPTP+FP=8080+100=80180≈0.444(44.4%)\text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}} = \frac{80}{80 + 100} = \frac{80}{180} \approx 0.444 \quad (44.4\%)

More than half of all triggered alerts (55.6%55.6\%) are false alarms! The Precision-Recall Area Under the Curve (AUPRC=0.71\text{AUPRC} = 0.71) exposes this weakness because its denominator contains only positive predictions (TP+FP\text{TP} + \text{FP}), completely unbuffered by the sea of true negatives.

One Number Hides

One shrug of accuracy loses to one shippable threshold.
One shrug of accuracy loses to one shippable threshold.

A single aggregate score like "accuracy 0.70" provides zero operational guidance. It fails to specify where the boundary lies, how many false alarms operations will handle daily, or what percentage of catastrophic events will slip through.

In production engineering, you cannot ship an abstract curve; you must ship a concrete, calibrated threshold parameter τ\tau:

  • Selecting τ=0.50\tau = 0.50 locks in an explicit service-level agreement (SLA): an F1F_1 score of 0.7270.727, an empirical interception rate of 4040 out of 6060 fraud attempts (66.7%66.7\%), and a guaranteed alert precision of 80%80\%.
  • When risk dynamics shift during high-traffic events (such as Black Friday sales), engineering teams can tune τ\tau dynamically (e.g., lowering to τ=0.40\tau = 0.40 to increase vigilance or raising to τ=0.70\tau = 0.70 if manual investigation queues overflow).

Miss or Alarm

Cheap misses lower the bar while cheap alarms raise it.
Cheap misses lower the bar while cheap alarms raise it.

Selecting an optimal operating point is ultimately an exercise in cost-sensitive optimization. Every classification error incurs an asymmetric business penalty:

E[Cost(τ)]=CFP⋅FP(τ)+CFN⋅FN(τ)\mathbb{E}[\text{Cost}(\tau)] = C_{\text{FP}} \cdot \text{FP}(\tau) + C_{\text{FN}} \cdot \text{FN}(\tau)

The optimal threshold τ∗\tau^* minimizes total expected financial and human cost:

τ∗=arg⁡min⁡τ[CFP⋅FP(τ)+CFN⋅FN(τ)]\tau^* = \arg\min_{\tau} \left[ C_{\text{FP}} \cdot \text{FP}(\tau) + C_{\text{FN}} \cdot \text{FN}(\tau) \right]

  • When Misses are Costly (CFN≫CFPC_{\text{FN}} \gg C_{\text{FP}}): In oncology screening or multi-million dollar wire transfers, missing a positive case is fatal. The cost of a false alarm is merely an automated second-tier review (CFP≈10 USDC_{\text{FP}} \approx 10\text{ USD}), whereas an undetected miss costs catastrophic liability (CFN≈50,000 USDC_{\text{FN}} \approx 50{,}000\text{ USD}). We lower the threshold (τ=0.20\tau = 0.20) to guarantee high recall (0.950.95).
  • When False Alarms are Costly (CFP≫CFNC_{\text{FP}} \gg C_{\text{FN}}): In automated account banning or mobile push notifications, crying wolf permanently damages customer trust and burns brand equity. We raise the threshold (τ=0.80\tau = 0.80) to demand strict statistical confidence, securing precision (0.920.92) while accepting lower recall (0.400.40).

Where It Breaks

Two models share one PR curve while one blocks far more good mail.
Two models share one PR curve while one blocks far more good mail.

Despite its diagnostic power on imbalanced data, the Precision-Recall curve has one fundamental mathematical blindspot:

Neither Precision (TPTP+FP\frac{\text{TP}}{\text{TP} + \text{FP}}) nor Recall (TPTP+FN\frac{\text{TP}}{\text{TP} + \text{FN}}) includes True Negatives (TN\text{TN}) in their formulas.

As a consequence, two distinct models can produce identical Precision-Recall curves (AUPRC=0.71\text{AUPRC} = 0.71) while behaving radically differently toward the negative background population:

  • Model A (Clean Discrimination): On 10,00010,000 clean customer emails, it accurately clears 9,9709,970 and falsely flags only 3030 legitimate users (0.3%0.3\% false alarm rate on negatives).
  • Model B (Diffuse Negative Leakage): On the exact same 10,00010,000 clean emails, it falsely blocks 300300 legitimate customers—a 10×10\times increase in collateral damage (3.0%3.0\% false alarm rate on negatives).

Because both models maintain the same ratio on the sampled positive test set, the PR curve cannot distinguish Model A from Model B. In production, always pair PR curves with True Negative monitoring and track the False Positive Rate (FPR=FP/N\text{FPR} = \text{FP} / N) or full cost contingency matrices before deploying.

The Quick Version

  • The Imbalance Trap: In a 99-to-1 negative split, an always-negative predictor achieves 99% accuracy while catching 0% of critical events.
  • Precision vs. Recall: Precision (TP/[TP+FP]\text{TP} / [\text{TP} + \text{FP}]) tracks alarm credibility; Recall (TP/[TP+FN]\text{TP} / [\text{TP} + \text{FN}]) tracks population coverage.
  • ROC vs. PR: ROC inflates perceived performance on imbalanced data because massive true negatives drown false positives in the FPR denominator; PR exposes low positive precision.
  • Shippable Decisions: Never deploy an abstract metric; ship a calibrated threshold dial τ\tau tied to concrete operational capacities.
  • Cost-Weighted Tuning: Lower τ\tau when misses carry catastrophic penalties (CFN≫CFPC_{\text{FN}} \gg C_{\text{FP}}); raise τ\tau when false alarms destroy customer trust (CFP≫CFNC_{\text{FP}} \gg C_{\text{FN}}).
  • The Negative Blindspot: PR formulas completely exclude True Negatives (TN\text{TN}). Always evaluate False Positive Rate alongside PR to prevent massive collateral damage on clean data.