F1 score for dummies

In the world of data science and machine learning, the evaluation of models is a crucial step. One common metric used to assess the performance of classification models is the F1 score.

If you’ve always been confused by the term, don’t worry! This article will provide a simple explanation of the F1 score, why it is important, and how to calculate it.

What is the F1 Score?

The F1 score is a measure of a model’s accuracy in classifying data. It is a single metric that combines two important aspects of classification: precision and recall.

In simpler terms, it tells us how well our model is at correctly identifying true positives (actual positive cases) while minimizing false positives and false negatives.

Why is the F1 Score Important?

While accuracy is a common way to measure the performance of a model, it can sometimes be misleading, especially when dealing with imbalanced datasets.

Imbalanced datasets are those in which the distribution of classes is not equal. In such cases, the F1 score becomes a more reliable metric because it takes into account both precision and recall.

Precision and Recall

To understand the F1 score, we first need to know what precision and recall are:

  1. Precision: Precision measures the proportion of true positives out of the predicted positive instances. It tells us how good our model is at correctly identifying positive cases.
  2. Recall: Recall measures the proportion of true positives out of the actual positive instances. It tells us how many of the positive cases our model is able to identify.

Calculating the F1 Score

Now that we understand precision and recall, calculating the F1 score is quite simple. The F1 score is the harmonic mean of precision and recall. The formula for the F1 score is as follows:

F1 Score = 2 * (Precision * Recall) / (Precision + Recall)

The F1 score ranges from 0 to 1, where 1 indicates a perfect classification model and 0 means the model failed to classify any instance correctly.


Let’s consider a hypothetical scenario to demonstrate the calculation of the F1 score. Suppose we have a model that classifies whether an email is spam or not. We have the following results:

  • True Positives (TP): 100
  • False Positives (FP): 30
  • False Negatives (FN): 20

First, we calculate precision and recall:

Precision = TP / (TP + FP) = 100 / (100 + 30) = 0.769 Recall = TP / (TP + FN) = 100 / (100 + 20) = 0.833

Now, we calculate the F1 score:

F1 Score = 2 * (0.769 * 0.833) / (0.769 + 0.833) = 0.8

In this case, our model has an F1 score of 0.8, which is a reasonably good performance.


The F1 score is a valuable metric for evaluating classification models, especially when dealing with imbalanced datasets.

By combining precision and recall into a single metric, it provides a more comprehensive view of a model’s performance.

Understanding the F1 score and how to calculate it is essential for anyone working with classification problems in data science and machine learning.

Leave a Comment