ML0012 F1 Score

What is F1 Score?

Answer

The F1 score is a metric for classification models that combines precision and recall into a single number, and it is particularly useful when classes are imbalanced. It is the harmonic mean of the two: precision measures how many positive predictions are correct, recall measures how many actual positives are found, and the harmonic mean punishes imbalance between them: a high F1 requires both to be high at once. A model with 99% precision but 10% recall scores poorly on F1, because the harmonic mean is dominated by the smaller of the two values. This makes F1 a stricter, more informative summary than accuracy or either component alone when false positives and false negatives both matter.

(1) Definition: The harmonic mean of precision and recall, one number summarizing both.
(2) Key Property: It is dominated by the lower component, so it cannot be gamed by maximizing only precision or only recall.
(3) When To Use: Imbalanced classes, or when false positives and false negatives carry comparable cost.

F1 score contour lines over the recall-precision plane

Figure 1: F1 contour lines over the recall–precision plane: to reach a higher F1 band you must improve both metrics: moving along one axis alone quickly flattens out.

Mathematical Formulation:
\text{F1} = \frac{2 \times \text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}
\text{F1} = \frac{2TP}{2TP + FP + FN}

Where:

  • \text{Precision} is TP/(TP+FP) and \text{Recall} is TP/(TP+FN) (see the precision-and-recall question).
  • TP, FP, and FN are the true positive, false positive, and false negative counts.
  • The second line is the equivalent counts-only form; TN does not appear, which is why F1 stays meaningful under class imbalance.

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *