🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #181

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.

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Precision – FAQs

Quick answers about learning Precision in Machine Learning.

This free note from CodingNow 2.0 explains Precision in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Precision, is 100% free with no signup required.
With focused practice, most students grasp Precision 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