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
Worked Example
Using the same confusion matrix (\(TP=15, FP=10\)):
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.