← Lessons

quiz vs the machine

Gold1340

Machine Learning

The Confusion Matrix And F1 Score

Go beyond accuracy with precision, recall, and their harmonic mean.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What does recall measure?

2. Why is the F1 score a harmonic mean?

3. Why can accuracy mislead on imbalanced data?