What is F1 score?
The F1 score is the harmonic mean of precision and recall, calculated as two times precision times recall, divided by the sum of precision and recall. Because it uses the harmonic mean rather than a simple average, a model scores well only when precision and recall are both high, and a low value in either one pulls the score down.
It is a common choice when a single number is needed to compare models and the classes are imbalanced, where plain accuracy can be misleading.
Key takeaways
- F1 balances precision and recall in one score using their harmonic mean.
- It is high only when both precision and recall are high.
- It is more informative than accuracy when the positive class is rare.
How it works
You compute precision and recall for a class at a chosen decision threshold, then take their harmonic mean. The harmonic mean is deliberately unforgiving: a model with excellent precision but poor recall, or the reverse, receives a low F1. Variants such as the F-beta score let you weight recall more or less heavily than precision when the costs of the two error types differ.
Why it matters
Accuracy can look excellent on imbalanced data simply by predicting the majority class, which hides poor performance on the cases that matter. F1 resists that by focusing on the positive class and penalizing lopsided precision-recall trade-offs, which makes it a practical headline metric for tasks like defect detection or rare-event classification.
Frequently asked questions
How is the F1 score calculated?
It is the harmonic mean of precision and recall: two times precision times recall, divided by precision plus recall.
Why use F1 instead of accuracy?
On imbalanced data, accuracy can be high while the model fails on the rare class. F1 focuses on the positive class and reflects that failure.
What is a good F1 score?
It is task dependent, and F1 is most useful for comparing models on the same dataset rather than as an absolute target.
Related terms