Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to Deep Learning Notes
Topic #335

Precision & Recall

Precision and recall answer two genuinely different questions about a classifier's positive predictions — and understanding the tradeoff between them is essential for choosing the right metric for any specific real-world stakes.

Formulas

\[ \text{Precision} = \frac{TP}{TP+FP}, \qquad \text{Recall} = \frac{TP}{TP+FN} \]
MetricQuestion It Answers
Precision"Of everything the model predicted positive, how much was actually positive?"
Recall (also called Sensitivity)"Of everything that was actually positive, how much did the model catch?"

Numerical Example

Continuing the spam example (TP=24, FP=7, FN=6):

\[ \text{Precision} = \frac{24}{24+7} = \frac{24}{31} \approx 0.774, \qquad \text{Recall} = \frac{24}{24+6} = \frac{24}{30} = 0.8 \]

77.4% of emails flagged as spam were actually spam (precision); 80% of all actual spam emails were successfully caught (recall).

The Tradeoff — Why You Rarely Get Both at Maximum

A classifier's positive/negative decision is typically based on thresholding a predicted probability (e.g. predict "positive" if \(\hat p > 0.5\)). Lowering this threshold flags more examples as positive — catching more true positives (raising recall) but also more false positives (lowering precision). Raising the threshold does the opposite. This threshold-driven tradeoff is exactly what the ROC and Precision-Recall curves, covered later in this category, visualize directly.

Choosing Which Matters More, by Context

ScenarioPriorityWhy
Spam detectionPrecisionA false positive (legitimate email marked spam) can mean a missed important message — costly
Cancer screeningRecallA false negative (missed cancer diagnosis) can be life-threatening — far costlier than a false positive requiring further (harmless) testing
Search engine result rankingPrecisionUsers care most about the relevance of the few results actually shown to them

Code

from sklearn.metrics import precision_score, recall_score

y_true = [1,1,1,1,1,0,0,0,0,0]
y_pred = [1,1,1,0,0,0,0,1,0,0]

print(precision_score(y_true, y_pred))   # TP / (TP + FP)
print(recall_score(y_true, y_pred))       # TP / (TP + FN)

Common Mistakes

  • Optimizing for precision or recall alone without considering the actual cost asymmetry of the task — the right balance is always context-dependent, never a universal default.
  • Reporting only one of the two metrics — a model can have excellent precision but terrible recall (or vice versa), and either number alone hides that imbalance; reporting both (or their combination, F1, next) gives a fuller picture.

Interview Relevance

Q: "Why would you prioritize recall over precision for a cancer-screening model, but precision over recall for a spam filter?" For cancer screening, a false negative (missing an actual cancer case) can be far more costly than a false positive (an unnecessary follow-up test) — prioritizing recall minimizes missed diagnoses. For spam filtering, a false positive (a legitimate email incorrectly marked spam) can mean missing something important, while a missed spam email (false negative) is a comparatively minor inconvenience — prioritizing precision minimizes that more costly error type.

Practice Question

Using the medical diagnosis confusion matrix from earlier (TP=45, FN=5, FP=15, TN=135), compute both precision and recall.

Related DL Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →