Calculate the F1 score, the harmonic mean of precision and recall.
The F1 score is the harmonic mean of precision and recall: F1 = 2 × (precision × recall) / (precision + recall). It's computed here directly from true positives (TP), false positives (FP), and false negatives (FN), where precision = TP / (TP + FP) measures how many predicted positives were correct, and recall = TP / (TP + FN) measures how many actual positives were found. The harmonic mean penalizes imbalance between precision and recall more than a simple average would, so F1 is high only when both metrics are reasonably strong — making it a popular single-number summary for classifiers, especially on imbalanced datasets.
F1 = 2 * (precision * recall) / (precision + recall)
The harmonic mean is much more sensitive to low values, so a classifier with high precision but very low recall (or vice versa) gets a low F1 score, whereas an arithmetic mean would hide that imbalance.
F1 is especially valuable on imbalanced datasets where accuracy can be misleadingly high just by predicting the majority class; F1 forces a balance between catching positives (recall) and avoiding false alarms (precision).
A perfect F1 score of 1.0 means both precision and recall are 1.0 — every predicted positive was correct, and every actual positive was found, with no false positives or false negatives.
F1 weighs precision and recall equally, while the more general F-beta score lets you weight recall beta times more heavily than precision (beta > 1) or vice versa (beta < 1), useful when one error type matters more than the other.