What Is the F1 Score and When to Use It
SkillVeris Team
AI Research Team

The F1 score is the harmonic mean of precision and recall, producing a single number between 0 and 1 that rewards a model only when both are high.
In this guide, you'll learn:
- It is calculated as F1 = 2 × (precision × recall) / (precision + recall).
- Because it uses the harmonic mean, F1 punishes extreme imbalance — a model strong in one metric but weak in the other scores poorly.
- F1 is especially useful on imbalanced datasets where accuracy is misleading.
- Use it when false positives and false negatives both matter and you want one metric to compare models.
1What Is the F1 Score?
The F1 score is a single metric that balances precision and recall by taking their harmonic mean. It ranges from 0 to 1, where 1 means perfect precision and recall and 0 means the model failed completely. Its purpose is to give you one number to optimize when you care about both catching positives and avoiding false alarms.
The harmonic mean is the key detail. Unlike a simple average, it stays low whenever either precision or recall is low, so a model cannot earn a high F1 by excelling at one while neglecting the other.
2How It Is Calculated
The F1 score has a compact formula that follows directly from precision and recall.
- F1 = 2 × (precision × recall) / (precision + recall)
- If precision = 0.8 and recall = 0.6, then F1 = 2 × (0.48) / (1.4) = 0.686.
- A simple average would give 0.7, so F1 sits slightly lower, pulled down by the weaker metric.
- F1 equals precision and recall only when the two are equal.
🔑Why Harmonic, Not Arithmetic?
The harmonic mean penalizes imbalance. With precision 1.0 and recall 0.0, an average gives 0.5 but F1 gives 0 — correctly reflecting a useless model.
3When to Use the F1 Score
The F1 score is most valuable in situations where accuracy would lie to you and where both error types carry weight.
- Imbalanced datasets, such as fraud or disease detection, where positives are rare.
- Problems where both false positives and false negatives are genuinely costly.
- Comparing several models when you need one number to rank them fairly.
- Information retrieval and search, where you want relevant results without too much noise.
When Not to Use It
If one error type clearly matters far more than the other, F1's equal weighting can mislead you. In cancer screening, where a miss is far worse than a false alarm, you may prefer to optimize recall directly, or use an F-beta score that favors it.
4F1 Score vs Accuracy
Accuracy measures the share of all predictions that are correct, which sounds ideal until your classes are imbalanced. On a dataset that is 99 percent negative, a model predicting 'negative' every time scores 99 percent accuracy while being completely useless.
F1 avoids that trap because it ignores true negatives entirely, focusing only on how well the model handles the positive class. On the same imbalanced dataset, the do-nothing model would score an F1 of 0, immediately revealing its worthlessness. This is why F1 is the default choice for rare-event detection.
5F-Beta: Tilting the Balance
The standard F1 weights precision and recall equally, but the more general F-beta score lets you tip the scale on purpose using a parameter called beta.
- F-beta = (1 + beta²) × (precision × recall) / (beta² × precision + recall)
- Beta = 1 gives the ordinary F1, weighting both equally.
- Beta > 1 (e.g. F2) weights recall more heavily — use when misses are costly.
- Beta < 1 (e.g. F0.5) weights precision more heavily — use when false alarms are costly.
6Common Mistakes to Avoid
The F1 score is powerful but often misused. Steer clear of these errors.
- Using F1 when one error type dominates — reach for F-beta or recall instead.
- Reporting F1 without also showing the underlying precision and recall.
- Comparing F1 scores computed with different averaging methods on multi-class problems (macro vs micro vs weighted).
- Assuming a high F1 means the model is good in absolute terms — it only balances two metrics.
- Forgetting that F1 depends on the chosen decision threshold.
💡Multi-Class Averaging
For more than two classes, macro-F1 treats every class equally while weighted-F1 accounts for class sizes. Choose deliberately and state which you used.
7Computing the F1 Score in Python
You rarely compute F1 by hand. Scikit-learn provides it directly and lets you pick an averaging strategy for multi-class problems.
- from sklearn.metrics import f1_score
- f1 = f1_score(y_true, y_pred) # binary case
- f1_macro = f1_score(y_true, y_pred, average='macro') # each class equal
- f1_weighted = f1_score(y_true, y_pred, average='weighted') # weighted by class size
- from sklearn.metrics import classification_report; print(classification_report(y_true, y_pred))
8Key Takeaways
Remember these essentials about the F1 score.
- F1 is the harmonic mean of precision and recall, a single number from 0 to 1.
- F1 = 2 × (precision × recall) / (precision + recall).
- It stays low unless both precision and recall are high, punishing imbalance.
- It shines on imbalanced data where accuracy misleads.
- Use F-beta when you need to weight recall or precision more heavily.
9Frequently Asked Questions
Q: What is a good F1 score? A: There is no universal threshold; it depends on the problem and its difficulty. Compare your F1 against a sensible baseline and against alternative models rather than against a fixed number, since a 'good' score in one domain may be poor in another.
Q: Why use the harmonic mean instead of a simple average? A: The harmonic mean stays close to the smaller of the two values, so it heavily penalizes a model that is strong in precision but weak in recall or vice versa. A simple average would reward such lopsided models too generously.
Q: When should I use F1 instead of accuracy? A: Use F1 when your dataset is imbalanced or when both false positives and false negatives matter. Accuracy can look excellent while the model fails on the rare positive class, whereas F1 exposes that failure.
Q: What is the difference between F1 and F2 scores? A: F1 weights precision and recall equally, while F2 is an F-beta score that weights recall roughly twice as much as precision. Choose F2 when missing positives is more costly than raising false alarms.
Related Reading
Get The Print Version
Download a PDF of this article for offline reading.
About the Publisher
SkillVeris Team
AI Research Team
Our AI team covers the latest in machine learning, generative AI, and emerging tech — clearly and accurately.
View all postsRelated Posts
Never miss an update
Get the latest tutorials and guides delivered to your inbox.
No spam. Unsubscribe anytime.