F1 Score
The F1 score combines precision and recall through their harmonic mean: F1 = 2 · (precision · recall) / (precision + recall). We cover its micro, macro and weighted variants, how it compares with accuracy and MCC, and its limits.
The F1 score is an evaluation metric for classification models that condenses precision and recall into a single number through their harmonic mean. The formula is F1 = 2 · (precision · recall) / (precision + recall), and its value runs from 0 to 1, only approaching the top when both components are high at once.
Born in information retrieval, it has become a machine learning staple, especially where plain accuracy misleads, as it does with imbalanced classes. It still pays to know its averaging variants and its blind spots before trusting a single number.
Precision, recall and why the harmonic mean
Both ingredients come from the confusion matrix. Precision is TP / (TP + FP): of everything the model labeled as positive, how much truly was. Recall is TP / (TP + FN): of all actual positives, how many the model retrieved. TP, FP and FN stand for true positives, false positives and false negatives.
The harmonic mean punishes any gap between the two: if one collapses, the F1 collapses with it, where an arithmetic mean would paper it over. A detector with precision 1.0 and recall 0.1 averages 0.55 arithmetically, yet its F1 barely reaches 0.18. Equivalently, the scikit-learn documentation writes it as F1 = 2 · TP / (2 · TP + FP + FN).
Micro, macro and weighted: F1 for multiclass and multilabel
In multiclass or multilabel problems you must decide how to average the per-class results, and scikit-learn defines three common strategies. Micro F1 aggregates the TP, FP and FN of every class into global totals and computes the metric on them, so every instance weighs the same. Macro F1 computes each class's F1 and takes the unweighted mean, giving minority classes the same weight as majority ones. Weighted F1 weights each class by its support, the number of true instances it has; it adjusts macro for label imbalance, though it can yield an F1 that does not sit between the global precision and recall.
F1 versus accuracy and MCC
Against accuracy, F1 holds up better under imbalance: a trivial classifier that always predicts the majority class earns high accuracy and yet a null F1 on the minority class. The Matthews correlation coefficient (MCC) goes further: it uses all four cells of the confusion matrix, including the true negatives that F1 ignores. Chicco and Jurman showed in BMC Genomics (2020) that MCC is more informative and reliable than F1 and accuracy on imbalanced datasets, because it only reaches high values when the model gets the majority of positives and the majority of negatives right, whereas F1 can return inflated, overoptimistic results.
Limits of F1 and the F-beta family
F1 ignores true negatives, changes if you swap which class counts as positive, and depends on the decision threshold used to binarize predictions, unlike ranking metrics such as AUC-ROC. When precision and recall do not matter equally, the F-beta family generalizes the formula: beta above 1 (as in F2) weights recall more heavily, and beta below 1 (as in F0.5) favors precision.
This article was produced with artificial intelligence under human editorial oversight.