The confusion matrix
A confusion matrix tabulates predictions against truth for classification.
- True positives are correctly flagged positives.
- False positives are negatives wrongly flagged as positive.
- False negatives are positives the model missed.
- True negatives are correctly identified negatives.
Why accuracy can mislead
On imbalanced data, accuracy lies. If one percent of emails are spam, always predicting not spam scores ninety nine percent accuracy while catching nothing.
Precision and recall
- Precision is the share of positive predictions that were correct. It punishes false alarms.
- Recall is the share of actual positives the model caught. It punishes misses.
- There is usually a tradeoff. Raising the threshold lifts precision but lowers recall.
The F1 score
The F1 score is the harmonic mean of precision and recall. The harmonic mean stays low unless both are high, so F1 rewards balance and is a strong single number for imbalanced classes.
Key idea
The confusion matrix exposes the kinds of errors, and the F1 score combines precision and recall into one balanced metric for imbalanced data.