Calcylator
F1 classification score

F1 classification score:
formula and worked example

One number for a classifier that has to be right when it flags something and also has to find most of what is there.

Calcylator Editorial Team

Updated · 5 min read

Why a single balanced score exists

Precision and recall pull in opposite directions. A classifier that flags only the cases it is most sure about will have high precision and poor recall; one that flags everything will have perfect recall and poor precision. Comparing models on one of these alone invites cheating by moving the threshold.

The F1 score ties the two together. It is high only when both are high, which makes it a common headline metric for tasks with rare positives, such as spam filtering, defect detection or entity extraction, where overall accuracy is dominated by the easy negatives.

It is not the only way to combine them, and it quietly assumes precision and recall matter equally. When they do not, a weighted variant is more honest.

A short history explains the choice of mean. In information retrieval the early question was how to rate a search system that returns a list: precision rewards a clean list and recall rewards a complete one. The harmonic mean was adopted because it behaves sensibly at the extremes, giving no credit to a system that returns the whole database just to reach perfect recall.

Formula and inputs

F1 classification score =2 × precision × recall ÷ (precision+recall)
precision:
Precision
recall:
Recall
Result is a score between 0 and 1. If either input is 0 the score is 0, and the score can never exceed the larger of the two inputs.
  • Precision: of everything the model flagged, the share that was correct, true positives divided by (true positives + false positives).
  • Recall: of everything that was really positive, the share the model found, true positives divided by (true positives + false negatives).

The expression is the harmonic mean of the two. In terms of raw counts it simplifies to 2 x TP divided by (2 x TP + FP + FN), which is a handy cross-check if you have the confusion matrix and not the ratios.

Be careful about which class counts as positive. In a binary problem F1 is normally computed for the minority or target class, and the score for the other class will be different. Say which one you report, or the figure cannot be reproduced.

Worked example: precision 0.8, recall 0.6

A document classifier flags items as relevant. Of the items it flags, 80% are relevant, and it finds 60% of all relevant items.

  • Precision

    0.8

  • Recall

    0.6

F1 classification score

0.685714 score

The arithmetic mean of 0.8 and 0.6 would be 0.7; the harmonic mean is lower because it leans towards the weaker input.

  1. Multiply precision and recall: 0.8 x 0.6 = 0.48.
  2. Double it: 2 x 0.48 = 0.96.
  3. Add the two inputs: 0.8 + 0.6 = 1.4.
  4. Divide: 0.96 / 1.4 = 0.685714, about 0.686.

What 0.686 tells you

A score of 0.686 sits between the two inputs and closer to recall, the weaker one. It tells you the model is moderately balanced but would benefit most from finding more of the real positives. An F1 of 1 would mean perfect precision and recall, and 0 means one of them is zero.

There is no universal good value. What passes for strong depends on how hard the task is, how noisy the labels are and what a human annotator would score on the same data. A more useful habit is to compare against a simple baseline and against the previous version of the model on the same test set.

Look also at the pair behind the score. An F1 of 0.686 might come from 0.8 and 0.6, or from 0.69 and 0.68; the first model flags carefully and misses a lot, while the second is evenly balanced, and they behave very differently in use.

If the score will be reported to non-specialists, pair it with one sentence of consequence: out of every 100 items that matter, this model finds about 60, and about 20 of every 100 items it flags are noise. That is more persuasive than any decimal.

Raising precision while recall stays put

F1 score when precision rises by 10% and recall stays at 0.6
ScenarioPrecisionCalculated result
Original assumptions0.80.685714 score
Precision increased by 10%0.880.713514 score

Lifting precision from 0.8 to 0.88 moves F1 from 0.6857 to 0.7135, a gain of about 0.028 for a precision rise of 0.08. The score responds less than one-for-one because recall is the bottleneck. Moving recall from 0.6 to 0.66 instead would give an F1 of about 0.723, a bigger improvement, showing that the weaker side is where effort pays more.

Where F1 misleads

  • Treating it as a measure of overall quality. It ignores true negatives, so a model can score well on F1 while performing poorly on the negative class.
  • Averaging F1 across classes without saying how. Macro averaging treats rare and common classes equally, while micro averaging weights by frequency, and they can give very different answers.
  • Using it when the costs of false positives and false negatives are clearly unequal. A weighted F-beta score or a cost-based metric fits better.
  • Comparing scores obtained on different datasets or class mixes as though they were on one scale.
  • Reporting a single score without the threshold it was computed at.

Choosing and tuning with F1

Suppose two spam filters both reach 0.69 F1. Filter A has precision 0.95 and recall 0.54; filter B has precision 0.55 and recall 0.93. For an inbox, where deleting a real message is painful, A may be preferred. For a moderation queue where missed abuse is costly, B may be better. The same F1 hides opposite behaviours, which is why teams often tune the threshold on a validation set and then report the full precision-recall pair.

Common questions

What is a good F1 score?

That depends on the task. On easy, clean problems scores above 0.9 are common, while hard extraction or detection tasks may be considered strong at much lower values. Compare against a baseline and against human agreement before judging.

Why is F1 a harmonic mean instead of an average?

A simple average would let a model with perfect recall and near-zero precision score about 0.5. The harmonic mean drops towards the smaller input, so the score stays low unless both precision and recall are reasonably high.

Does F1 account for true negatives?

No. Precision and recall are computed only from true positives, false positives and false negatives. This is helpful when negatives are abundant, and a limitation when correct rejection of negatives matters in itself.

When should I use F-beta instead of F1?

Use it when one type of error costs more. A beta greater than 1 weights recall more heavily, which suits situations where a miss is worse, and a beta below 1 weights precision, which suits costly false alarms.

Can F1 be higher than precision or recall?

Never; it lies between the two inputs. In this example it falls at 0.686 between 0.6 and 0.8, and it equals both only when the two inputs are identical.

Was this guide helpful?

Continue reading

View all blogs