What Is the F1 Score?
The F1 score is a single metric that combines precision and recall into one number, making it a popular way to evaluate classification models in machine learning, information retrieval, and statistics. It is the harmonic mean of precision and recall, so it rewards classifiers that balance the two rather than excelling at only one.
How to Use This Calculator
Enter three counts from your confusion matrix: True Positives (TP, correctly predicted positives), False Positives (FP, negatives wrongly predicted positive), and False Negatives (FN, positives that were missed). The calculator instantly returns precision, recall, and the resulting F1 score.
The Formula Explained
Precision = \( \frac{\text{TP}}{\text{TP} + \text{FP}} \) measures how many predicted positives were correct. Recall = \( \frac{\text{TP}}{\text{TP} + \text{FN}} \) measures how many actual positives were found. The F1 score is then
$$ F_1 = \frac{2 \cdot (\text{precision} \cdot \text{recall})}{\text{precision} + \text{recall}} $$Because it is a harmonic mean, a low value in either precision or recall pulls the F1 score down sharply.
Worked Example
Suppose \( \text{TP} = 70 \), \( \text{FP} = 30 \), \( \text{FN} = 10 \). Precision = \( \frac{70}{100} = 0.70 \). Recall = \( \frac{70}{80} = 0.875 \).
$$ F_1 = \frac{2 \cdot (0.70 \cdot 0.875)}{0.70 + 0.875} = \frac{2 \cdot 0.6125}{1.575} \approx 0.7778 $$or about 77.78%.
F1 Score Across Different Precision and Recall Scenarios
F1 is the harmonic mean of precision and recall: \(F_1 = \frac{2PR}{P+R}\). The table compares it with the simple arithmetic mean for several precision (P) and recall (R) pairs.
| Precision | Recall | Arithmetic Mean | F1 |
|---|---|---|---|
| 0.90 | 0.90 | 0.900 | 0.900 |
| 0.99 | 0.50 | 0.745 | ≈ 0.664 |
| 0.80 | 0.60 | 0.700 | ≈ 0.686 |
| 1.00 | 0.10 | 0.550 | ≈ 0.182 |
| 0.50 | 0.50 | 0.500 | 0.500 |
The 0.80/0.60 row corresponds, for example, to TP = 60, FP = 15, FN = 40: precision = 60/75 = 0.80, recall = 60/100 = 0.60, and \(F_1 = \frac{2 \cdot 60}{2 \cdot 60 + 15 + 40} = \frac{120}{175} \approx 0.686\).
Note: F1 always lies closer to the lower of the two values than the arithmetic mean does. When precision and recall are equal, F1 equals both. The more they differ, the more F1 is pulled down toward the weaker one, so a model cannot hide poor recall behind excellent precision (or the reverse).
Confusion Matrix Terms and Related Metrics
- True Positive (TP): a positive case that the model correctly predicted as positive.
- False Positive (FP): a negative case wrongly predicted as positive (a false alarm, Type I error).
- False Negative (FN): a positive case wrongly predicted as negative (a miss, Type II error).
- True Negative (TN): a negative case correctly predicted as negative. TN is not used in the F1 formula.
- Precision (positive predictive value): \(\frac{TP}{TP + FP}\), the share of predicted positives that are truly positive.
- Recall (sensitivity, true positive rate): \(\frac{TP}{TP + FN}\), the share of actual positives that the model finds.
- Accuracy: \(\frac{TP + TN}{TP + TN + FP + FN}\), the share of all predictions that are correct. It can be misleading on imbalanced data.
- Specificity (true negative rate): \(\frac{TN}{TN + FP}\), the share of actual negatives correctly identified.
- F-beta score: \(F_\beta = \frac{(1+\beta^2) PR}{\beta^2 P + R}\). F1 is the case \(\beta = 1\). F2 (\(\beta = 2\)) weights recall more heavily; F0.5 (\(\beta = 0.5\)) weights precision more heavily.
- Macro averaging: compute F1 for each class and take the unweighted mean, so every class counts equally.
- Micro averaging: pool TP, FP and FN across all classes and compute one F1, so frequent classes dominate.
- Weighted averaging: average the per-class F1 scores weighted by each class's number of true instances (support).
Interpreting Your F1 Score
F1 ranges from 0 (no true positives) to 1 (no false positives and no false negatives). As a rough, informal guide:
- About 0 to 0.5: weak
- 0.5 to 0.7: moderate
- 0.7 to 0.9: good
- Above 0.9: very strong
These bands are context-dependent and no universal standard exists. An F1 of 0.6 may be excellent for a hard task such as rare-event detection with noisy labels, while 0.95 may be inadequate in a safety-critical setting.
What a gap between precision and recall means
- Low precision, higher recall: the model finds most positives but raises many false alarms.
- Low recall, higher precision: the model's positive predictions are reliable, but it misses many actual positives.
Check both values rather than relying on F1 alone, since the same F1 can come from very different precision/recall combinations.
Limitations to keep in mind
- F1 ignores true negatives, so it says nothing about how well the model handles the negative class.
- It depends on class balance. The same model can score differently on datasets with different positive rates.
- It depends on the decision threshold. Changing the threshold trades precision against recall and moves F1.
- Always compare against a baseline, such as a majority-class or always-positive predictor, or a simple existing model, to judge whether the score is a real improvement.
FAQ
When should I use F1 instead of accuracy? F1 is preferred when classes are imbalanced, since accuracy can be misleadingly high when one class dominates.
What is a good F1 score? F1 ranges from 0 to 1; closer to 1 is better. What counts as "good" depends on the task, but values above 0.8 are often considered strong.
Why is it a harmonic mean? The harmonic mean penalizes extreme imbalance between precision and recall more than a simple average would, ensuring both must be reasonably high.