What is precision?
Precision is the proportion of predictions labeled positive that are actually positive. It answers: *“When the classifier raises a positive alert, how often is it correct?”*
Formula
Precision = TP / (TP + FP)- TP (true positives): correctly predicted positive examples.
- FP (false positives): negative examples incorrectly predicted positive.
TP + FPis the total number of positive predictions, not the total number of examples.
Precision is also called positive predictive value (PPV).
Beginner-friendly numerical example: fraud alerts
A fraud model flags 50 bank transactions as suspicious. Investigators confirm that:
- 40 flagged transactions were actually fraudulent (TP = 40).
- 10 flagged transactions were legitimate (FP = 10).
Precision = 40 / (40 + 10)
= 40 / 50
= 0.80 = 80%Interpretation: for every 10 fraud alerts, approximately 8 are genuine fraud and 2 are false alarms in this evaluated sample.
What this does not tell you: how many fraudulent transactions the classifier missed. That requires recall, which uses false negatives and is covered in the next question.
When does high precision matter?
Precision is useful when false-positive alerts are expensive, such as when positive predictions trigger human review, automatically block legitimate users, or interrupt an important workflow. High precision helps limit unnecessary alerts.
However, a classifier can reach high precision by making very few positive predictions, so precision must be interpreted alongside the number of alerts and recall.
Python example
PYTHONfrom sklearn.metrics import precision_score # 40 true positives and 10 false positives among 50 alerts y_true = [1] * 40 + [0] * 10 + [1] * 20 + [0] * 30 y_pred = [1] * 50 + [0] * 50 print(precision_score(y_true, y_pred, pos_label=1)) # 0.8
The examples outside the first 50 alerts do not change precision because they are predicted negative.
Important details
- Positive class: decide which label means “positive”; with nonstandard labels, set
pos_labelexplicitly. - Decision threshold: changing the threshold can change the number and composition of positive predictions, so precision can rise or fall.
- No positive predictions: if
TP + FP = 0, precision is mathematically undefined. scikit-learn exposes azero_divisionsetting to handle that case. - Multiclass tasks: define how classwise precision values are combined (for example, macro or weighted averaging) rather than assuming one binary-class formula describes every class.
In short: precision tells you how trustworthy positive predictions are, not how many of all actual positives were found.
References
Learning Sequence
Machine Learning Curriculum
Explore Related Questions
Deepen your understanding across related Machine Learning topics.