📏  Micro F1

Micro F1#

F1 computed from globally pooled TP/FP/FN; dominated by the more frequent classes.

Important

✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.

What it is#

The F1 score is the harmonic mean of precision and recall, rewarding a model only when both are high:

\[F_1 = \frac{2 \cdot \text{Precision} \cdot \text{Recall}} {\text{Precision} + \text{Recall}}.\]

Micro F1 extends F1 to \(K\) classes by pooling counts before computing the score, rather than averaging per-class F1 values (which is macro F1).

How it’s computed#

First form global precision and recall by summing true/false positives and false negatives over all classes:

\[\text{Precision}_{\text{micro}} = \frac{\sum_i TP_i}{\sum_i (TP_i + FP_i)}, \qquad \text{Recall}_{\text{micro}} = \frac{\sum_i TP_i}{\sum_i (TP_i + FN_i)},\]

then combine them with the F1 formula:

\[F_{1,\text{micro}} = \frac{2 \cdot \text{Precision}_{\text{micro}} \cdot \text{Recall}_{\text{micro}}} {\text{Precision}_{\text{micro}} + \text{Recall}_{\text{micro}}}.\]

A key identity#

In single-label (multi-class) problems, micro precision, micro recall and micro F1 are all equal — and equal to plain accuracy. With one label per sample, a false positive for one class is the same event as a false negative for another, so the pooled denominators coincide. (In multi-label problems they can differ.)

Worked example#

Three classes with TP = (40, 30, 10), FP = (10, 20, 20), FN = (10, 20, 30):

  • \(\text{Precision}_{\text{micro}} = 80/130 \approx 0.615\)

  • \(\text{Recall}_{\text{micro}} = 80/140 \approx 0.571\)

  • \(F_{1,\text{micro}} \approx 0.592\)

When to use it#

Micro F1 measures overall, sample-weighted performance and lets majority classes dominate — handy on imbalanced data when overall throughput matters. Use macro F1 when every class should count equally, including rare ones.

In code#

from sklearn.metrics import f1_score

micro = f1_score(y_true, y_pred, average="micro")
macro = f1_score(y_true, y_pred, average="macro")

Theme: Classification & Averaging Metrics  ·  All terminology


Hint

Mind map — connected ideas

Macro F1 · Micro Precision · Micro Recall · Micro AUROC · Multi-label Classification


See also

Source article Adapted (context, re-expressed) in our own words from: Micro F1 (insightful-data-lab.com).

Tags: purpose: reference topic: terminology level: intermediate