Recommended resources
The freely available resources this lesson will direct you to.
- Why is the Formula for F1-Score Unnecessarily Complicated?www.youtube.com
- Stanford CS229: Machine Learning | Summer 2019 | Lecture 21 - Evaluation Metricswww.youtube.com
- Essential Things You Need to Know About F1-Scoretowardsdatascience.com
- An Intuitive Guide To The F1 Score | Towards Data Sciencetowardsdatascience.com
Welcome back. In our previous lesson, we dissected a classifier's performance using the confusion matrix, defining accuracy, precision, and recall. We concluded by identifying a fundamental tension: the precision-recall trade-off. Improving one often comes at the expense of the other, leaving us with a difficult choice. How do we objectively compare a model with high precision and low recall against one with the opposite profile, especially when the costs of false positives and false negatives are roughly equivalent?
This lesson directly addresses that challenge. We will introduce the F1-score, a metric designed to synthesize precision and recall into a single, robust number. Our goal is not just to compute this score, but to develop a deep, theoretical understanding of why it is formulated the way it is. We will discover that the F1-score is the harmonic mean of precision and recall, and we will explore the specific mathematical properties that make this type of average uniquely suited for this task.
The Problem with Simple Averages
When faced with the need to combine two numbers, the most intuitive first step is to take their arithmetic mean. What if we defined a score as simply ? While simple, this approach has critical flaws.
The video below from the ritvikmath channel takes a wonderfully constructive approach, starting with this naive idea and systematically exposing its weaknesses. This process of building up from first principles will help solidify why a more sophisticated metric is necessary.
Why is the Formula for F1-Score Unnecessarily Complicated?
This video explores different ways to combine precision and recall, starting with the most intuitive but flawed methods.
Please watch the segment that analyzes the arithmetic mean. As you watch, focus on two key critiques: What score does the arithmetic mean assign to a model with 90% precision but 0% recall? Does this score feel representative of a useful model? The video describes the trade-off as "constant" or "linear." What does this mean, and why is it a problem for evaluating a classifier?
As the video demonstrates, the arithmetic mean is unsatisfying. It assigns a misleadingly high score (0.45 in the example) to a useless model with zero recall. Furthermore, its linear nature means it treats an improvement from 0% to 10% recall the same as an improvement from 90% to 100%. Intuitively, the former represents a far more significant gain. We need a metric that is more sensitive, especially to poor performance in either precision or recall.
Defining the F1-Score: The Harmonic Mean
The F1-score resolves these issues by using a different kind of average: the harmonic mean.
The formal definition of the F1-score is:
This can also be expressed as the reciprocal of the arithmetic mean of the reciprocals of precision and recall:
Let's apply this to a concrete example.

In this example, the model is trying to identify malignant cases (the positive class). From the table, we have:
- True Positives (TP): 1 (Correctly identified as Malignant)
- False Positives (FP): 1 (Benign case incorrectly flagged as Malignant)
- False Negatives (FN): 1 (Malignant case missed, predicted as Benign)
- True Negatives (TN): 7 (Correctly identified as Benign)
The precision and recall are calculated as:
- Precision = or 50%
- Recall = or 50%
Now, we can compute the F1-score:
In this specific case, since precision and recall are equal, the F1-score is also equal to them. Note how the F1-score (50%) paints a much more sobering picture of the model's performance on the positive class than the overall accuracy (80%).
Building Intuition: Why the Harmonic Mean?
The choice of the harmonic mean is deliberate and mathematically motivated. It has properties that make it far superior to the arithmetic mean for this purpose. To build a solid intuition, we will first explore the harmonic mean through a classic analogy and then analyze its mathematical behavior.
An Analogy: The Race of Two Halves
The following article from Towards Data Science provides a brilliant analogy to understand the nature of the harmonic mean.
An Intuitive Guide To The F1 Score | Towards Data Science
This article uses a simple physics riddle to demystify the harmonic mean and connect it directly to the F1-score.
Please read from the beginning, starting with the introduction, which outlines two key properties of the F1-score. Then, continue through the section that presents the riddle about average speed. Finally, read the part that connects the riddle's solution directly to the F1-score formula.
The "race of two halves" analogy is powerful because it reveals the core property of the harmonic mean: it is biased towards the smaller value. Your average speed over the whole race is closer to your slower speed because you spend more time running at that slower speed. Similarly, the F1-score is pulled down more significantly by the lower of the two values (precision or recall). A model cannot achieve a high F1-score by excelling at one metric while failing at the other; it must be competent at both.
A Mathematical and Visual Perspective
Let's return to the ritvikmath video to see how the harmonic mean formula directly addresses the flaws of the simpler averages.
Why is the Formula for F1-Score Unnecessarily Complicated?
This video will now show how the harmonic mean formulation solves the issues identified earlier with the arithmetic mean.
Please watch the segment that introduces and analyzes the harmonic mean. Pay close attention to the plot comparing the F1-score curve to the linear arithmetic mean curve. Notice two crucial behaviors: The F1-score is 0 if recall is 0, regardless of how high precision is. The curve shows "diminishing returns." The gain in F1-score is steepest when recall is low and flattens out as recall approaches 1.
The harmonic mean inherently "punishes" extreme imbalances between precision and recall. To visualize this, we can compare it to the arithmetic and geometric means.
The article "Essential Things You Need to Know About F1-Score" provides a clear comparison.
Essential Things You Need to Know About F1-Score
This article offers another perspective, comparing the harmonic mean against other types of means to justify its use in the F1-score.
Please read the sections titled "Motivation Behind F1-Score" and "What is F1-Score?" to formalize the definition. Then, focus on the section "Why Harmonic Mean?", which explains why this specific average is chosen over others.
As explained in the reading, if a model has a perfect recall (1.0) but a dismal precision (e.g., 0.05), the means would be:
- Arithmetic Mean: (1.0 + 0.05) / 2 = 0.525 (misleadingly high)
- Geometric Mean:
- Harmonic Mean (F1): (appropriately low)
The harmonic mean most severely penalizes the imbalance, yielding a score that better reflects the model's poor performance in precision.
This "penalizing" behavior can be visualized as a surface. While the arithmetic mean forms a flat plane, the harmonic mean creates a curved surface that dips sharply towards zero if either input value is low.

For completeness, and given your theoretical interest, the first article we read also includes the formal proofs for why the F1-score is always bounded by precision and recall, and why it's always less than or equal to the arithmetic mean.
An Intuitive Guide To The F1 Score | Towards Data Science
This section of the article provides the formal mathematical arguments for the properties of the F1-score we've discussed intuitively.
Please review the section that begins with "Okay, time for proofs." These proofs use contradiction to rigorously establish the behavior of the harmonic mean in this context.
Conclusion
In this lesson, we have elevated our evaluation toolkit by introducing the F1-score. We established that it serves as a necessary and robust way to balance the competing demands of precision and recall, especially in scenarios with imbalanced classes or symmetric error costs. Most critically, we have delved into the theoretical justification for its formula.
Here are the key takeaways:
- The F1-score is the harmonic mean of precision and recall, providing a single metric to summarize the precision-recall trade-off.
- Unlike the arithmetic mean, the harmonic mean is strongly biased towards the smaller of its two inputs. This means a model must have both high precision and high recall to achieve a high F1-score.
- If either precision or recall is zero, the F1-score is also zero. This correctly reflects that the model has failed in a critical way.
- The F1-score is particularly valuable for evaluating models on imbalanced datasets, where accuracy can be highly misleading.
The F1-score gives us a powerful way to assess a model at a single decision threshold. However, a model's output is typically a score or probability, and the threshold is our choice. How does performance change as we vary this threshold? Answering this question allows for an even more comprehensive model evaluation. In our next lesson, we will explore the Receiver Operating Characteristic (ROC) curve and the Area Under the Curve (AUC), which do exactly that.