Skip to content
Optimal Lab

AI · interactive

Precision, recall and F1

A spam classifier gives each of 20 emails a score. Above the threshold, it's flagged as spam. Accuracy alone hides the two different mistakes: blocking real mail, and letting spam through.

score 0flagged as spam →1

Red: really spam. Green: real email.

Spam caught (TP)

8

Real mail blocked (FP)

4

Spam missed (FN)

2

Real mail delivered (TN)

6

Precision
67%
Recall
80%
F1
73%
Accuracy
70%

Of 12 flagged, 8 are spam (precision 67%). Of 10 spam emails, 8 were caught (recall 80%).

  1. 1

  2. 2

  3. 3

    F1 is their harmonic mean, a single number that punishes ignoring either. Accuracy misleads when classes are unbalanced.

    99% accuracy is easy if 99% of mail is fine.

  4. 4

In production

Tools and technologies

Classification metrics apply to LLM features too.

Not tied to one language — use these names when you search docs or design a system.