F1 Score.

The harmonic mean of precision and recall, providing a single balanced metric that equally weighs both false positives and false negatives in classification tasks.

The F1 score is a fundamental evaluation metric in machine learning that combines precision and recall into a single balanced measure for classification and information extraction tasks. Unlike simple accuracy, which can be misleading with imbalanced datasets, the F1 score provides a more nuanced assessment by considering both the model's ability to avoid false positives (precision) and its ability to catch all relevant instances (recall). This makes it particularly valuable when both types of errors carry significant costs and when you need a single number to compare model performance.

Mathematically, the F1 score is calculated as the harmonic mean of precision and recall: F1 = 2 × (precision × recall) / (precision + recall). The harmonic mean is used rather than the arithmetic mean because it penalizes extreme values more heavily, meaning a model cannot achieve a high F1 score by excelling in just one metric while performing poorly in the other. The score ranges from 0 to 1, where 1 represents perfect precision and recall, and values closer to 1 indicate better overall performance. This balanced approach makes the F1 score particularly useful for binary classification, multi-class problems, and named entity recognition tasks.

In practice, the F1 score is especially valuable when dealing with imbalanced datasets where accuracy alone would be misleading, such as fraud detection or medical diagnosis where positive cases are rare but critical to identify. However, the equal weighting of precision and recall may not always align with business objectives—sometimes false positives are more costly than false negatives or vice versa. In such cases, practitioners often use weighted variants like F-beta scores that allow for different emphasis on precision versus recall, or they evaluate precision and recall separately alongside the F1 score to get a complete picture of model performance.