๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #146

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.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Precision & Recall โ€“ FAQs

Quick answers about learning Precision & Recall in Deep Learning.

This free note from CodingNow 2.0 explains Precision & Recall in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Precision & Recall, is 100% free with no signup required.
With focused practice, most students grasp Precision & Recall in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now