Skip to main content

Precision and Recall

Topic — Overall accuracy treats false positives (false alarms) and false negatives (missed cases) as identical errors. In reality, their business costs are rarely symmetrical. This guide explores Precision (selectivity against false alarms) and Recall (sensitivity to positive instances), proves why they exist in a fundamental mechanical tradeoff governed by the decision threshold τ\tau, and details Specificity and the Four-Way Metric Symmetry.


1. The Core Concept​

When evaluating a binary classifier, we must evaluate two competing operational perspectives:

  1. Precision (Positive Predictive Value): Of all instances the model labeled as positive, what fraction was actually positive? Precision=TPTP+FP=True PositivesTotal Predicted Positives\text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}} = \frac{\text{True Positives}}{\text{Total Predicted Positives}}

    • Focus: Minimizing False Positives (Type I Errors). High precision guarantees that when the system raises an alarm, you can trust it.
  2. Recall (Sensitivity, True Positive Rate): Of all actual positive cases in the population, what fraction did the model successfully detect? Recall=TPTP+FN=True PositivesTotal Actual Positives\text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}} = \frac{\text{True Positives}}{\text{Total Actual Positives}}

    • Focus: Minimizing False Negatives (Type II Errors). High recall guarantees that few true positive instances slip through undetected.
tip

If you only take one thing from this page

Precision is about quality of positive predictions (few false alarms). Recall is about quantity of positive cases captured (few missed cases). Lowering the decision threshold raises Recall but lowers Precision; raising the threshold raises Precision but lowers Recall.


2. Interactive Precision-Recall Threshold Simulator​

Slide the decision threshold τ\tau across a 100-sample test cohort (40 actual positives, 60 actual negatives) to observe how the balance between false alarms and missed cases shifts:

Precision-Recall Threshold Simulator

Move the decision threshold cutoff to visualize the mechanical tradeoff:

Decision Threshold (τ):0.50
Precision (Selectivity)56.1%
TP / (TP + FP) = 32 / 57
Recall (Sensitivity)80.0%
TP / (TP + FN) = 32 / 40
Harmonic Mean (F1-Score)0.660
2 · (P · R) / (P + R)
Balanced Operational Regime

Balanced compromise with F1 = 0.660. Tolerates 25 false alarms while capturing 32 of 40 positive cases.


3. When to Prioritize Which Metric​

The choice between optimizing Precision vs. Recall depends entirely on the asymmetry of operational costs:


  • The Cost Asymmetry: False Negatives (missed cases) are dangerous, fatal, or irreversible. False Positives (false alarms) merely incur minor review overhead.
  • Domain 1: Medical Cancer Screening: Missing an early-stage malignant tumor (FN) leads to untreated disease and mortality. A false alarm (FP) is cleared with an ultrasound.
  • Domain 2: Airport Security Threat Detection: Missing a prohibited weapon (FN) compromises flight safety. A false alarm (FP) takes 30 seconds of manual bag inspection.
  • Domain 3: Financial Fraud: Approving a $50,000 fraudulent wire (FN) causes immediate financial loss. A false alarm (FP) sends a one-time confirmation SMS to the cardholder.
  • Tuning Rule: Lower threshold τ\tau (e.g. τ=0.10−0.30\tau = 0.10 - 0.30) to cast a wide net.

4. The Four-Way Metric Symmetry​

Together with Specificity and Negative Predictive Value (NPV), Precision and Recall form a balanced 2x2 mathematical symmetry:

PerspectivePositive FocusNegative Focus
Row Perspective (Actual Classes)Recall (Sensitivity / TPR):
TPActual Positives=TPTP+FN\frac{\text{TP}}{\text{Actual Positives}} = \frac{\text{TP}}{\text{TP} + \text{FN}}
Specificity (TNR):
TNActual Negatives=TNTN+FP\frac{\text{TN}}{\text{Actual Negatives}} = \frac{\text{TN}}{\text{TN} + \text{FP}}
Column Perspective (Predicted Classes)Precision (PPV):
TPPredicted Positives=TPTP+FP\frac{\text{TP}}{\text{Predicted Positives}} = \frac{\text{TP}}{\text{TP} + \text{FP}}
Negative Predictive Value (NPV):
TNPredicted Negatives=TNTN+FN\frac{\text{TN}}{\text{Predicted Negatives}} = \frac{\text{TN}}{\text{TN} + \text{FN}}

Complementary Error Rates​

  • False Positive Rate (FPR): FPR=1−Specificity=FPTN+FP\text{FPR} = 1 - \text{Specificity} = \frac{\text{FP}}{\text{TN} + \text{FP}} (Fraction of healthy people falsely alarmed).
  • False Negative Rate (FNR / Miss Rate): FNR=1−Recall=FNTP+FN\text{FNR} = 1 - \text{Recall} = \frac{\text{FN}}{\text{TP} + \text{FN}} (Fraction of sick people overlooked).

5. Implementation Lab​

tip

Lab Exercise: Precision, Recall & Threshold Tuning

An interactive, fully functional Google Colab / Jupyter Notebook is available to calculate Precision and Recall across spam and disease cohorts, and sweep decision thresholds τ∈[0.25,0.75]\tau \in [0.25, 0.75] live in your browser.

Open In Colab

How to run the lab:

  1. Click the "Open In Colab" badge above to launch the interactive notebook.
  2. Run cells sequentially to simulate threshold adjustments and track metric shifts.

Key Experiments to Run:

  • Experiment 1 (Spam Filter Verification): Compute Precision (77.8%77.8\%) and Recall (70.0%70.0\%) on 20 emails using precision_score and recall_score.
  • Experiment 2 (Medical Screening Tradeoff): Evaluate how catching 13/1513/15 sick patients (86.7%86.7\% Recall) incurs 88 false alarms (61.5%61.5\% Precision), validating clinical tolerance for Type I errors.
  • Experiment 3 (Threshold Sweep): Sweep τ\tau from 0.250.25 to 0.750.75 across 100 beta-distributed probability scores to observe Recall plunging from 97.5%97.5\% to 35.0%35.0\% as Precision climbs from 52.7%52.7\% to 73.7%73.7\%.

6. Common Mistakes​


  • The Misconception: "Precision and Recall have the same denominator since both start with TP in the numerator."
  • Wrong Thinking: Dividing TP by total correct or mixing predicted and actual counts.
  • The Right Principle: Precision divides by Predicted Positives (TP+FP\text{TP} + \text{FP}, the column total). Recall divides by Actual Positives (TP+FN\text{TP} + \text{FN}, the row total).

7. Summary​

Metric Perspectives

  • Precision: TPTP+FP\frac{\text{TP}}{\text{TP} + \text{FP}}. Answers: When I flag positive, how often am I right?
  • Recall: TPTP+FN\frac{\text{TP}}{\text{TP} + \text{FN}}. Answers: Of all real positive cases, how many did I catch?
  • Specificity: TNTN+FP\frac{\text{TN}}{\text{TN} + \text{FP}}. Answers: Of all real negatives, how many did I clear?
  • F1-Score: Harmonic mean balancing Precision and Recall into a single scalar.

Engineering Tradeoffs

  • Lower Threshold (τ < 0.5): Catches more positives (Recall ↑), accepts more false alarms (Precision ↓).
  • Raise Threshold (τ > 0.5): Avoids false alarms (Precision ↑), misses borderline cases (Recall ↓).
  • High-Recall Domains: Medicine, fraud, disaster alerts (FN is dangerous).
  • High-Precision Domains: Auto-delete spam, loan denial, recommender systems (FP is costly).

info

Key Takeaways

  • Tradeoff is mechanical: Adjusting the classification threshold τ\tau moves the operational point along the Precision-Recall curve.
  • Align to cost asymmetry: If false negatives kill or cost millions, tune for Recall; if false alarms destroy customer trust or incur legal liability, tune for Precision.
  • Never report one in isolation: A 100% Recall model can be trivial (predict everything positive); always report Precision alongside Recall or combine them via the F1-Score.

Next Section: F-Scores and Balanced Metrics - synthesizing precision and recall via the harmonic mean, FβF_\beta weighting, and MCC.


8. Active Recall​

Test your understanding by answering first, then clicking to reveal the underlying principles.

Interactive Checkpoint Quiz​

Interactive Checkpoint: The Threshold Adjustment Decision

A hospital deploys an automated sepsis early-warning classifier. Clinicians complain that the model misses 20% of deteriorating patients (False Negatives), but when it does trigger an alert, it is correct 95% of the time (Precision = 95%). What threshold adjustment should the engineering team make?

Review Flashcards​

1. [THEORY] Why does lowering a classifier's decision threshold mechanically increase Recall while decreasing Precision?

  • More Positives Declared: Lowering τ\tau broadens the criteria for predicting positive (y^=1\hat{y} = 1).
  • Effect on Recall: Borderline true positive cases that previously scored below τ\tau are now captured as True Positives, reducing FN→0\text{FN} \to 0 and driving Recall=TPTP+FN→100%\text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}} \to 100\%.
  • Effect on Precision: Borderline true negative cases are also swept into positive predictions, increasing False Positives (FP↑\text{FP} \uparrow) and diluting Precision=TPTP+FP\text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}}.
2. [MATH] A model evaluates 200 samples: TP = 70, FP = 10, FN = 30, TN = 90. Calculate Precision, Recall, and Specificity.

  • Precision: TPTP+FP=7070+10=7080=0.875\frac{\text{TP}}{\text{TP} + \text{FP}} = \frac{70}{70 + 10} = \frac{70}{80} = 0.875 (87.5%87.5\%).
  • Recall: TPTP+FN=7070+30=70100=0.700\frac{\text{TP}}{\text{TP} + \text{FN}} = \frac{70}{70 + 30} = \frac{70}{100} = 0.700 (70.0%70.0\%).
  • Specificity: TNTN+FP=9090+10=90100=0.900\frac{\text{TN}}{\text{TN} + \text{FP}} = \frac{90}{90 + 10} = \frac{90}{100} = 0.900 (90.0%90.0\%).
3. [ANALYZE] Why is high Precision prioritized over Recall in automated content moderation (e.g., auto-banning toxic user accounts)?

  • Cost Asymmetry: Banning an innocent user permanently (False Positive) creates intense customer outrage, PR backlash, and potential support tickets.
  • Letting a mildly toxic comment slip through (False Negative) is an acceptable compromise that can be addressed via manual community flagging later.
  • Automated account actions require extreme precision (99%+99\%+) before applying automated punitive actions.
4. [PRACTICE] In an imbalanced fraud dataset (1% fraud), what is the precision of a naive random guessing baseline?

  • Prevalence Rate: The baseline precision of a random or constant positive guesser is equal to the positive class prevalence: Baseline Precision=Actual PositivesTotal Samples=1100=1.0%\text{Baseline Precision} = \frac{\text{Actual Positives}}{\text{Total Samples}} = \frac{1}{100} = 1.0\%
  • If a complex neural net achieves 30%30\% precision on this dataset, it represents a massive 30x diagnostic improvement over random guessing, even though 30%30\% sounds low in the abstract.
5. [THEORY] What is the difference between Specificity and Negative Predictive Value (NPV)?

  • Specificity (TNR): Row perspective. TNTN+FP\frac{\text{TN}}{\text{TN} + \text{FP}}. Measures how effectively the model clears actual healthy people. Independent of class prevalence.
  • Negative Predictive Value (NPV): Column perspective. TNTN+FN\frac{\text{TN}}{\text{TN} + \text{FN}}. Answers: When the model predicts 'Negative', what is the probability the patient is truly healthy? Heavily dependent on class prevalence.