Skip to content

[FAQ] Homework 4 (2026): Why does the maximum F1 threshold (0.41) not match the Precision-Recall intersection (0.63)? #486

Open

Description

@c-ibarra

Course

machine-learning-zoomcamp

Question

In Homework 4, Question 3 identifies the decision threshold where Precision and Recall intersect (0.63), while Question 4 finds the threshold that maximizes the F1-score (0.41).

Why does the maximum F1-score not occur at the intersection where Precision equals Recall?

Answer

A common intuition is that the harmonic mean ($F_1$) is always highest where precision and recall are equal ($P \approx R$). In practice, this is rarely true, especially on imbalanced datasets or models with asymmetric score distributions.

The $F_1$-score formula is:
$$F_1 = 2 \cdot \frac{P \cdot R}{P + R}$$

Comparing the two thresholds on the validation set:

  1. Precision–Recall intersection (threshold = 0.63):

    • $Precision = 0.733$, $Recall = 0.725$
    • Here, the costs of False Positives and False Negatives are balanced ($|P - R| \approx 0.0075$).
    • Resulting $F_1 \approx 0.729$.
  2. Maximum $F_1$ threshold (threshold = 0.41):

    • Lowering the threshold to 0.41 boosts Recall to 0.976 while Precision drops to 0.619.
    • Because $F_1$ is driven by the product $P \cdot R$, the $+25.1%$ gain in recall significantly outweighs the $-11.4%$ loss in precision.
    • Resulting $F_1 = \mathbf{0.758}$ (the global maximum).

Conclusion:
Balancing Precision and Recall ($P \approx R$) minimizes the gap between metrics, but does not necessarily maximize the harmonic mean ($F_1$). The optimal $F_1$ threshold frequently favors recall when capturing positive cases yields a net gain in the harmonic mean.

Checklist

  • I have searched existing FAQs and this question is not already answered
  • The answer provides accurate, helpful information
  • I have included any relevant code examples or links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions