06 · Metrics
F1
Precision's dependence, plus a cost that moves when the model improves.
Precision and recall pull against each other, so the natural next move is to combine them and report one number. F1 is that number, and it is probably the most widely reported single metric in machine learning under class imbalance.
It inherits everything from the previous section, which is expected. It also adds something of its own, which is not, and which is much harder to see.
The missing cell
F1 is the harmonic mean of precision and recall, which weights the smaller of the two more heavily than an ordinary average would.
Substituting the two definitions and simplifying gives the form worth staring at.
Three of the four cells of the confusion matrix appear.
This design is deliberate and traces back to the F1 score's origins in Information Retrieval. When a query retrieves a few relevant documents from a corpus of billions, the vast number of correctly ignored documents are practically irrelevant. A search engine deserves no credit for the billions of pages it successfully excludes.
So the first thing to ask of F1 is whether that description fits. If correctly identifying a negative case has real value, F1 is the wrong metric, and the reason has nothing to do with imbalance. A screening programme that reassures a healthy patient has done something useful, and F1 will not record it.
What it inherits
F1 is built from precision, and precision carries a prevalence term, so F1 carries one too. Writing the three cells in terms of the rates, with
The prevalence sits in the denominator, so F1 falls as positives get rarer, for the same reason precision did. Richardson et al. confirm it empirically, through an experiment in which, at a fixed threshold, F1 moves as the class mix changes (Richardson et al., 2024).
Take the same operating point as the previous section,
Precision moved from
That is worth stating carefully, because it is the source of a common and understandable mistake. Moving less is not the same as not moving. F1 is more stable than precision under a change in the class mix, and it is not invariant to it. A metric that is merely less sensitive still cannot be compared across populations with different base rates.
The cost it adds
Now the part that belongs to F1 alone. Sections 03 and 04 each ended by asking where the metric puts its threshold, because that is where a metric states what a mistake costs. Accuracy answered 1/2 (one half). Balanced accuracy answered
Suppose the score is a calibrated probability, and consider flagging a small group of cases that all carry posterior
Until now all
- The
positives were misses and are now catches, so gains and loses the same . Formally, and . - The
negatives were correct rejections and are now false alarms, so gains . That is and .
Write
The denominator grows by
At the optimum the threshold and the score agree, so the F1-maximising threshold satisfies
The threshold F1 asks for is half the F1 score we happen to achieve. Not half of something fixed in advance. Half of the metric's own value, which is a property of the model.
Why it lands there
The identity looks arbitrary until you notice that
Look again at what one extra flagged case does. It adds exactly
Adding something to a ratio raises that ratio only when the thing you add is itself a bigger ratio. So flagging one more case helps when
Reading the curve
That rule draws the shape in the figure below. Start at the far left, with
Now raise
The dashed line is
Read the consequence slowly, because I at least did not understand a thing when I first read this. Two teams work on the same problem, in the same hospital, facing the same consequences for a missed case. One team's model is better. F1 tells them to act at different thresholds. The cost of a mistake has not changed. The metric's opinion about it has, and it changed because of something that has no bearing on what harm a false alarm does.
Line the three up. Each is a claim about what to do, and they get progressively harder to notice:
- Accuracy acts above
. A commitment, stated once, at least inspectable. - Balanced accuracy acts above
. A commitment handed over to whichever evaluation set was used. - F1 acts above
. A commitment handed over to the model being evaluated.
Nobody wrote any of the three down. The third is the one that could not have been written down, because it is not knowable until after the model is trained.
The problem, stated plainly
In practice, misclassifications carry tangible real-world costs. A missed case is worth a specific number of false alarms. The F1 score ignores this reality. It provides no parameter to input domain-specific costs, instead it enforces an implicit cost ratio of
What makes this implicit cost even worse is that it's unstable. It drifts whenever we train a better model or evaluate on a dataset with a different base rate (prevalence
This creates a flaw for model selection in that choosing the candidate with the highest F1 score inherently compares models at different thresholds. Evaluating each under its own arbitrary assumption about what a mistake costs. The winning model may simply be the one whose implied cost happened to artificially flatter its performance.
Beta, and what to do instead
The usual response to this is
While
When F1 is the right choice
Two conditions, and they are the ones information retrieval satisfies.
- True negatives genuinely carry no value, so deleting that cell costs nothing.
- There is no predefined penalty for errors, and the system simply delivers a ranked list to a decision maker who determines the cutoff point.
Under these constraints, F1 serves as a reasonable summary of top-ranking performance. Its failure to encode a fixed cost is not a vulnerability here, but an honest reflection of a costless environment. However, it should always be reported alongside the class prevalence used during computation.
Step outside of that specific search-engine scenario, and the core problem remains. Every metric we have examined so far is just a threshold rule with a hidden cost buried inside it. The next section stops trying to pick a single threshold altogether, and instead explores how we can evaluate a model across every possible threshold at once.