Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #1708

Precision

Precision answers: "of everything the model flagged as positive, how much was actually positive?" — the right metric when false positives are the costly, undesirable error.

Formula

\[ \text{Precision} = \frac{TP}{TP+FP} \]

Worked Example

Using the same confusion matrix (\(TP=15, FP=10\)):

\[ \text{Precision} = \frac{15}{15+10} = \frac{15}{25} = 0.6 \]

Of every transaction the model flagged as fraud, only 60% actually were — the other 40% were false alarms on legitimate transactions.

from sklearn.metrics import precision_score

y_true = [1]*20 + [0]*80
y_pred = [1]*15 + [0]*5 + [1]*10 + [0]*70

print(precision_score(y_true, y_pred))   # 0.6

When Precision Is the Metric That Matters Most

High precision matters most when a false positive is costly or disruptive: flagging a legitimate customer's card as fraudulent (annoying, can lose their trust), marking a legitimate email as spam (they miss an important message), recommending an unnecessary and invasive medical procedure. In all these cases, you want to be confident before acting on a positive prediction.

The Precision-Recall Tradeoff, Briefly

Precision and recall usually move in opposite directions as you shift the classification threshold — being more "cautious" about calling something positive raises precision (fewer false alarms) but typically lowers recall (more missed true cases). This tradeoff is explored fully in Precision-Recall Curve.

Practical Use Cases

  • Spam filtering — a false positive (blocking a real email) is often worse than a false negative (one spam email slipping through)
  • Content recommendation — recommending something irrelevant (false positive) damages user trust more than missing one good recommendation

Common Mistakes

  • Optimizing for precision alone without checking what happens to recall — a model can trivially achieve perfect precision by predicting positive only for the single most obvious case, catching almost nothing.
  • Confusing precision with accuracy — precision only considers predicted positives, ignoring true negatives entirely.

Interview Relevance

Q: "When would you optimize for precision over recall?" When false positives carry a higher cost than false negatives — e.g. flagging a legitimate transaction as fraud and blocking a customer's card is more damaging to the business than occasionally missing a smaller fraud case, so a fraud team focused on customer experience might prioritize precision.

Practice Question

Given \(TP=40, FP=5\), compute precision by hand and interpret what it means in plain language.

Related ML Notes

Want to go beyond the notes?

Join CodingNow's Machine 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 →