F1 score

The F1 score is a number between 0 and 1 that combines a classification model's precision and recall into one measure by taking their harmonic mean.

Precision asks: of the cases the model flagged, how many were right? Recall asks: of the cases that really were positive, how many did the model catch? The F1 score combines them as two times precision times recall, divided by precision plus recall. This harmonic mean stays close to whichever of the two is lower. A model with 90% precision but 10% recall gets an F1 of 0.18, not the 0.5 a simple average would suggest, so a model cannot score well by excelling at one and neglecting the other.

F1 is popular where the thing being looked for is rare, such as fraud, disease or a named person in a document. There, accuracy flatters a model that predicts nothing, while F1 ignores the large pile of true negatives and focuses on the positive cases. Google's Machine Learning Crash Course recommends it when precision and recall need to be balanced, especially on imbalanced data. A general version, F-beta, lets one weigh recall more heavily than precision or the other way round.

The measure comes from information retrieval, the study of search systems. Its name is thought to come from a different F function in C. J. van Rijsbergen's 1979 book Information Retrieval, and the F-measure was introduced at the fourth Message Understanding Conference, MUC-4, in 1992. It remains standard in language processing tasks such as named entity recognition.

It has known weaknesses. Because it ignores true negatives, it can mislead when both classes matter. It weighs precision and recall equally, while in practice a missed cancer and a false alarm rarely cost the same. Some researchers, including Davide Chicco and Giuseppe Jurman in 2020, argue that the Matthews correlation coefficient is more informative. For tasks with several classes, check whether a reported F1 is macro-averaged, treating every class equally, or micro-averaged, pooling all predictions, since the two can differ a lot.

Common questions

What is a good F1 score?

It ranges from 0 to 1, where 1 means perfect precision and recall. What counts as good depends on the task and on what existing methods achieve; a score that is excellent for a hard, rare-event problem might be poor for an easy one.

What is the difference between F1 score and accuracy?

Accuracy counts all correct predictions, including the many true negatives in an imbalanced dataset. F1 only considers performance on the positive class, through precision and recall, so it is harder to inflate by always predicting the common class.

What is the difference between macro and micro F1?

Macro F1 calculates the score for each class separately and averages them, so rare classes count as much as common ones. Micro F1 pools all predictions before calculating, so common classes dominate. Reports should say which was used.

Why use the harmonic mean instead of the average?

The harmonic mean is pulled towards the smaller value. That stops a model from earning a respectable score by having very high precision and very low recall, or the reverse.

Finding more

Search for "F1 score explained", "precision recall F1" or "macro vs micro F1". Machine learning courses, library documentation such as scikit-learn's and information retrieval textbooks give exact definitions and examples. When comparing F1 scores across studies, check that they used the same dataset, the same averaging method and the same positive class.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.