Precision, Recall, and F1
Precision, recall, and their harmonic mean F1 measure classifier quality where raw accuracy misleads on imbalanced data.
Why accuracy is not enough
On imbalanced data, accuracy deceives: a classifier that always predicts the majority class can score 99% while catching none of the rare cases that matter. Precision, recall, and F1 look past overall accuracy to how well the positive class is found and how often positive predictions are right.
The definitions
- Precision = TP / (TP + FP): of everything predicted positive, how much was actually positive.
- Recall (sensitivity) = TP / (TP + FN): of all actual positives, how many were caught.
- F1 = 2 * precision * recall / (precision + recall): the harmonic mean, high only when both are high.
These are read from the confusion matrix of true/false positives and negatives.
The tradeoff
Precision and recall pull against each other. Raising the decision threshold makes the model predict positive only when confident: precision rises, recall falls. Lowering it catches more positives at the cost of more false alarms. Which to favor depends on costs: recall matters when missing a positive is dangerous (disease screening, disruption detection), precision matters when false alarms are expensive.
| Predict Pos | Actual Pos | Outcome |
|---|---|---|
| yes | yes | TP |
| yes | no | FP |
| no | yes | FN |
| no | no | TN |
Choosing and averaging
F1 balances the two into one number for model selection when you cannot rank precision above recall. For multiple classes, macro-averaging weights each class equally (good when rare classes matter), while micro-averaging weights by frequency. To see behavior across all thresholds rather than one, use the precision-recall curve or the ROC/AUC.