Computing Library › Machine Learning
Machine Learning

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

Kronos motion — lego machine

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 PosActual PosOutcome
yesyesTP
yesnoFP
noyesFN
nonoTN

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.