F1 score: formula, example, and limitations
The F1 score is the harmonic mean of precision and recall: F1 = 2TP / (2TP + FP + FN). It summarises performance on a chosen positive class and does not include true negatives.
Worked example: with 40 true positives, 10 false positives, and 20 false negatives, precision is 40/50 = 0.80, recall is 40/60 ≈ 0.667, and F1 is 80/110 ≈ 0.727. Report the class and decision threshold alongside the score.
F1 is not automatically the best metric for imbalanced data. Check precision and recall separately when errors have different costs. For multiclass tasks, specify whether you use macro, micro, or weighted averaging; see the official F1 documentation.
Learn to evaluate models honestly. Read the free Starter Kit excerpt on test sets before deciding whether the €19 handbook is right for you.

What is the F1 Score?
The F1 score is a powerful machine learning metric that combines precision and recall into a single number. It’s particularly useful when you’re dealing with imbalanced datasets or when you need to find an optimal balance between precision and recall.
How is the F1 Score Calculated?
The F1 score is the harmonic mean of precision and recall. Here’s the formula:
F1 = 2 * (Precision * Recall) / (Precision + Recall)
But what do precision and recall mean? Let’s break it down:
- Precision: The proportion of true positive predictions among all positive predictions.
- Recall: The proportion of true positive predictions among all actual positive instances.
Learn more about precision and recall on Machine Learning Mastery
Why Use the F1 Score?
The F1 score is particularly valuable when:
- You have an uneven class distribution
- You want to balance false positives and false negatives
- You need a single metric to compare different models
Related: Precision vs Recall · The Confusion Matrix in Python · ROC Curves in Machine Learning. Want the full picture? Chapter 13 of the ML Starter Kit, Evaluating a Model Honestly, walks you through evaluating classifiers step by step.
Interpreting the F1 Machine Learning Metric
The F1 score ranges from 0 to 1, where:
- 1 is the best possible score
- 0 is the worst
A higher F1 score indicates better overall performance of your machine learning model.
Conclusion on the F1 Machine Learning Metric
Understanding the F1 score is crucial for anyone working in machine learning. It provides a balanced measure of a model’s performance, especially when dealing with imbalanced datasets. By mastering this metric, you’ll be better equipped to evaluate and improve your machine learning models.
Remember, while the F1 score is powerful, it’s just one tool in your machine learning toolkit. Always consider multiple metrics and the specific needs of your project when evaluating model performance.
As always, thank you very much for reading How to Learn Machine Learning, happy modeling, and may your F1 scores always be high! 🚀📊

Subscribe to our awesome newsletter to get the best content on your journey to learn Machine Learning, including some exclusive free goodies!



