Precision
Precision is the share of positive predictions that are correct: TP / (TP + FP). How prevalence moves it, how detectors count it, and how to raise it.
Precision is the share of a model's positive predictions that are correct. It answers the question "when the model says yes, how often is it right?" and is calculated as true positives divided by all positive predictions: precision = TP / (TP + FP), where a false positive (FP) is a negative case the model wrongly flagged. Precision runs from 0 to 1, so a precision of 0.95 means 1 in 20 alerts is a false alarm. Positive predictive value (PPV) is a synonym used in medicine, and the false discovery rate equals 1 minus precision. Precision matters most when false alarms are costly, such as a spam filter that hides real email, an inspection system that scraps good parts, or a security camera that calls guards for shadows.
How Precision Is Calculated#
Precision reads two cells of the confusion matrix: the true positives and the false positives, which together make up every positive prediction. Missed positives never enter the formula, so a model that flags only its single most certain case can reach a precision of 1.0 while finding almost nothing. Precision is therefore reported alongside recall, TP / (TP + FN), which penalizes exactly those misses, and the F1-score combines the two in one number. When a model makes no positive predictions at all, precision is 0 / 0 and undefined, and libraries such as scikit-learn report it as 0 with a warning.
With more than two classes, precision is computed per class, treating that class as positive and everything else as negative, and then averaged. Macro precision weights every class equally, and in single-label multi-class tasks micro-averaged precision equals accuracy.
Precision Depends on Prevalence#
Recall and specificity describe how a model treats positives and negatives separately, so they stay fixed when positives become rarer. Precision mixes the two groups and falls as prevalence falls, because the same false positive rate applied to more negatives produces more false alarms per true detection. The scikit-learn script below scores one screening model at two prevalences:
import numpy as np
from sklearn.metrics import accuracy_score, precision_score, recall_score
# One screening model at two prevalences: it finds 90% of positives and flags 1% of negatives
for positives in (1000, 100):
negatives = 10_000 - positives
tp, fp = int(0.9 * positives), int(0.01 * negatives)
counts = [tp, positives - tp, fp, negatives - fp] # TP, FN, FP, TN
# Rebuild labels and predictions for 10,000 cases from the confusion-matrix counts
y_true = np.repeat([1, 1, 0, 0], counts)
y_pred = np.repeat([1, 0, 1, 0], counts)
accuracy = accuracy_score(y_true, y_pred)
recall = recall_score(y_true, y_pred)
precision = precision_score(y_true, y_pred)
print(f"{positives} positives: accuracy {accuracy:.3f}, recall {recall:.2f}, precision {precision:.2f}")With 1,000 positives in 10,000 cases, the model reaches a precision of 0.91. With 100 positives, its recall is still 0.90 and its accuracy even rises to 0.989, but 99 false alarms now stand beside 90 true detections, and precision drops to 0.48. A precision measured on a balanced test set therefore overstates the precision a model will show in deployment wherever positives are rarer, such as screening for a rare disease.
Precision in Object Detection#
In object detection, every predicted box above the confidence threshold is a positive prediction. Predictions are matched in order of descending confidence, and a box is a true positive only if it overlaps a labeled object of the same class with an intersection over union (IoU) at or above the threshold and that object has not already been claimed by a higher-scoring box. Boxes on background, boxes with the wrong class, loosely placed boxes, and duplicate boxes on an already matched object all count as false positives.
Raising the confidence threshold removes low-scoring boxes, which are more often wrong, so precision usually rises as recall falls. Plotting precision against recall across every threshold traces the precision-recall curve, and the area under it is the average precision (AP) that mean average precision (mAP) averages over classes and, for mAP50-95, over ten IoU thresholds. YOLO26 validation saves the precision of each class at every confidence threshold as BoxP_curve.png and reports precision (P) at the confidence where mean F1 peaks, next to recall and mAP.
Improving Precision#
- Raise the confidence threshold: The fastest fix, paid for with lower recall.
- Add hard negatives: Add the look-alike objects and empty scenes that trigger false alarms to the training data so the model learns what not to flag. Selecting the most confusing negatives this way is called hard negative mining.
- Fix missing labels: A correct detection of an object the annotator skipped counts as a false positive, so incomplete ground-truth labels make precision look worse than it is.
- Separate confused classes: The confusion matrix shows which classes the model mixes up, and more examples or clearer class definitions for those pairs remove the wrong-class false positives.
Precision vs. Related Terms#
- Recall: The share of actual positives the model finds, TP / (TP + FN). It counts misses, and precision counts false alarms.
- Specificity: The share of actual negatives correctly rejected, TN / (TN + FP). Specificity of 0.99 can still yield a precision below 0.5 when positives are rare, as the screening script shows.
- Accuracy: The share of all predictions that are correct, dominated by the majority class in imbalanced data.
- Numerical precision: The number of bits used to store each value, such as 32-bit or 16-bit floating point, an unrelated meaning of the same word.
- Precision in measurement: How closely repeated measurements agree with each other, where accuracy describes how close they are to the true value. A scale that always reads 2 kg too heavy is precise but inaccurate.










