F1-Score

Machine Learning
Introduced by
C. J. van Rijsbergen
Year
1979
Type
Evaluation metric
Family
Classification Metric

What does it do?

The F1-score is the harmonic mean of precision and recall, so it is high only when both are high.

It is computed from the counts of true positives, false positives and false negatives, and it is widely used to summarise binary classifiers and information retrieval systems. The measure is attributed to C. J. van Rijsbergen's work on information retrieval.

The intuition behind the method

Precision and recall often pull in opposite directions. A classifier can raise precision by predicting the positive class only when it is very certain, which usually lowers recall, or raise recall by predicting positive more often, which usually lowers precision. The F1-score combines the two into one value using the harmonic mean, which is pulled strongly toward the smaller of the two numbers. For example, with precision 0.99 and recall 0.01, the arithmetic mean is 0.50, but F1 is about 0.02. If recall is exactly 0, F1 is exactly 0 whatever the precision, and a small recall gives a value close to zero. Because the score is driven by precision and recall alone, a large number of true negatives cannot inflate it, which is why it is often preferred over accuracy when the positive class is rare.

History

The F-measure is attributed to C. J. van Rijsbergen's book Information Retrieval, where it was used to combine precision and recall in evaluating document retrieval. The F1-score is the case in which precision and recall are weighted equally; F-beta variants allow other weightings, giving recall β² times the importance of precision.

When to use it

Choose F1 when the positive class is the focus, when false positives and false negatives both matter, and when you need one number to compare classifiers on the same data. It suits binary classification with a skewed class distribution, where accuracy can be dominated by the majority class, and detection or retrieval tasks in which relevant items are sparse. Do not use it when true negatives matter, for example when correctly rejecting negatives is central to the task, when false positives and false negatives have very different costs (a weighted variant such as F-beta-score may fit better), or when there is no meaningful positive class. For multi-class problems, state which averaging scheme is used and why.

Limitations and considerations

  • F1 ignores true negatives, so it says nothing about specificity or about how many negatives are correctly rejected.
  • Precision and recall weight false positives and false negatives equally in the usual form of the score; when their costs differ substantially, F1 does not reflect that unless a weighted variant such as F-beta-score is used.
  • Precision depends on the positive-class prevalence, so F1 values computed on datasets with different positive-class rates are not directly comparable.
  • F1 is computed at a single decision threshold and does not describe how the classifier behaves at other thresholds.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Because F1 is a harmonic mean, a classifier cannot reach a high score by excelling at precision while ignoring recall, or the reverse.
  • F1 ignores true negatives, so a large majority class does not inflate the score the way it can inflate accuracy on skewed data.
  • The value is determined entirely by the counts of true positives, false positives and false negatives, so it is easy to recompute from a confusion matrix.
  • It gives a single scalar that is simple to compare across model variants evaluated on the same test set.

Applications

  • Text classification and sentiment analysis, where both missing relevant documents (low recall) and including irrelevant ones (low precision) are problems.
  • Medical diagnosis, where missing cases (low recall) and false alarms (low precision) both have significant costs.
  • Named entity recognition in NLP, where both finding all entities and being accurate about boundaries matter.
  • Recommendation systems, where finding good recommendations (recall) and avoiding bad ones (precision) are both important.

How it works

How it works

1

Count the true positives (TP), false positives (FP) and false negatives (FN) for the positive class from the confusion matrix. The F1-score is then F1 = 2TP / (2TP + FP + FN).

Formula
\mathrm{F}_1 = \frac{2\,\mathrm{TP}}{2\,\mathrm{TP} + \mathrm{FP} + \mathrm{FN}}
2

Compute precision = TP / (TP + FP) and recall = TP / (TP + FN), then take the harmonic mean: F1 = 2 * (precision * recall) / (precision + recall). The two forms give the same value.

Formula
\mathrm{F}_1 = \frac{2 \cdot \mathrm{Precision} \cdot \mathrm{Recall}}{\mathrm{Precision} + \mathrm{Recall}}
3

F1 ranges from 0 to 1. A value of 1.0 means precision and recall are both perfect. A value of 0 means precision or recall is exactly 0. Because the harmonic mean is pulled toward the smaller input, a high F1 requires both precision and recall to be reasonably high, not just one of them.

Common pitfalls

  • Treating F1 as a universal metric without checking the cost of each error type in the application.
  • Reporting one macro-averaged F1 for a multi-class problem without checking per-class scores, which can conceal a class that performs poorly.
  • Confusing F1-score with balanced accuracy. F1 depends on precision and recall, while balanced accuracy depends on sensitivity and specificity, so the two can rank models differently.
  • Reporting F1 without stating which class is the positive class. Swapping which class is labelled positive changes the value, because F1 is built from the counts of the positive class only and true negatives never enter the formula. An F1 reported for a minority class should be labelled as such, not presented as a symmetric summary of both classes.

Frequently asked questions

Why use the harmonic mean instead of the arithmetic mean of precision and recall?

The harmonic mean is pulled strongly toward the smaller of the two values. If precision is 0.99 and recall is 0.01, the arithmetic mean is 0.50, but the harmonic mean (F1-score) is approximately 0.02, which reflects that the model finds only about 1% of the positive cases. The harmonic mean penalizes imbalance between precision and recall.

How does F1-score differ from balanced accuracy?

F1-score depends on precision and recall, which focus on positive predictions. Balanced accuracy is the average of recall (sensitivity to positive cases) and specificity (sensitivity to negative cases). F1-score ignores true negatives, while balanced accuracy weighs both types of correct predictions equally.

When should I use macro-averaged vs. micro-averaged F1 on multi-class problems?

Use macro-averaged F1 when all classes should count equally, so rare classes carry as much weight as common ones. Use micro-averaged F1 when every individual decision should count equally, so frequent classes dominate. For single-label multi-class problems, where each example has exactly one true class and one predicted class, micro-averaged F1 equals accuracy; this equivalence does not hold in general for multi-label settings.

Related methods

Sources

  1. van Rijsbergen, C. J. (1979). Information Retrieval (2nd ed.). Butterworth-Heinemann.

    Open publication reference
  2. Powers, D. M. (2011). Evaluation: From Precision, Recall and F-Measure to ROC, Informedness, Markedness and Correlation. Journal of Machine Learning Technologies, 2(1), 37-63.

    Open publication reference
  3. understanding-machine-learning-theory-algorithms, p. 244