The F1 score combines precision and recall into a single number using their harmonic mean. It is useful when you need one metric to compare models and both error types matter. Its defining property is that it punishes imbalance: a model with excellent precision and terrible recall scores poorly, which a simple average would hide.
Key takeaways
- F1 = 2 × (precision × recall) ÷ (precision + recall).
- It ranges from 0 to 1, where 1 means perfect precision and recall.
- The harmonic mean is used because it is dominated by the smaller value.
- F-beta variants let you weight recall or precision more heavily.
- F1 ignores true negatives and depends on the chosen threshold.
F1 explained in simple terms
Two sales candidates: one makes many calls but closes nothing, the other closes everything but calls almost no one. Averaging their scores makes both look mediocre-to-fine. The harmonic mean says both are poor, because performance requires doing both. F1 applies that logic to precision and recall.
Why the harmonic mean
Compare a model with precision 0.9 and recall 0.1:
| Mean type | Calculation | Result |
|---|---|---|
| Arithmetic | (0.9 + 0.1) ÷ 2 | 0.50 |
| Harmonic (F1) | 2 × (0.9 × 0.1) ÷ (0.9 + 0.1) | 0.18 |
The arithmetic mean suggests a middling model. F1 correctly reports that it is nearly useless, because it finds only a tenth of real cases. The harmonic mean is always pulled towards the lower value, which is exactly the behaviour you want.
A worked example
A support ticket classifier for the “urgent” category:
- TP = 80, FP = 40, FN = 20
- Precision = 80 ÷ 120 = 0.667
- Recall = 80 ÷ 100 = 0.800
- F1 = 2 × (0.667 × 0.800) ÷ (0.667 + 0.800) = 1.067 ÷ 1.467 = 0.727
Now compare two models:
| Model | Precision | Recall | Arithmetic mean | F1 |
|---|---|---|---|---|
| A | 0.95 | 0.55 | 0.75 | 0.70 |
| B | 0.73 | 0.72 | 0.725 | 0.72 |
By arithmetic mean A looks better; by F1 B wins, because it is balanced. Whether that is the right conclusion depends on your costs, which is the key caveat below.
F-beta: weighting one side
When one error type matters more, use F-beta:
Fβ = (1 + β²) × (precision × recall) ÷ (β² × precision + recall)
| Variant | β | Effect | Use when |
|---|---|---|---|
| F0.5 | 0.5 | Weights precision twice as much | False alarms are expensive |
| F1 | 1 | Equal weight | Both matter similarly |
| F2 | 2 | Weights recall twice as much | Missing cases is expensive |
Medical screening often uses F2; spam filtering often uses F0.5.
Multi-class averaging
| Average | How it works | Use when |
|---|---|---|
| Macro F1 | Mean of per-class F1 scores, unweighted | Rare classes matter as much as common ones |
| Weighted F1 | Weighted by class support | You want overall performance reflecting class sizes |
| Micro F1 | Pools TP, FP and FN across classes | Equivalent to accuracy in single-label problems |
Macro F1 is usually the honest choice for imbalanced business problems, because it refuses to let a large easy class hide failure on a small important one.
When F1 is the wrong metric
- The error costs are unequal. F1 assumes precision and recall matter equally. If a missed fraud costs ₹8,000 and a false alarm costs ₹500, a cost-weighted metric is better.
- True negatives matter. F1 ignores them entirely; consider the Matthews correlation coefficient (MCC), which uses all four confusion matrix cells.
- You want threshold-independent comparison. Use PR-AUC or ROC-AUC instead.
- You need calibrated probabilities. Use log loss or calibration plots.
- Regression problems. F1 does not apply; use MAE or RMSE.
Practical guidance
- Report precision, recall and F1, never F1 alone.
- State the threshold and the averaging method used.
- Use F-beta when costs are clearly asymmetric.
- Compare against a sensible baseline, such as always predicting the majority class.
- Compute F1 per subgroup to check for uneven performance.
Limitations
- Assumes equal importance of precision and recall.
- Ignores true negatives, so it cannot express the value of correct rejections.
- Tied to a single threshold.
- A single number inevitably hides where a model fails.
