The F1 score is a classification metric equal to the harmonic mean of precision and recall, computed as F1 = 2 * precision * recall / (precision + recall). In model evaluation for artificial intelligence, it summarizes in one number how well a classifier finds the positive cases while avoiding false alarms, and it ranges from 0 (worst) to 1 (perfect).
F1 is popular because accuracy is misleading on imbalanced data. When only 2 percent of transactions are fraudulent, a model that labels everything as legitimate reaches 98 percent accuracy and is useless. F1 ignores true negatives entirely, so it rewards a model only for correctly handling the rare positive class.
How the F1 score is calculated
F1 is built from the four cells of a confusion matrix: true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN). Precision is TP divided by all predicted positives, and recall is TP divided by all actual positives. F1 combines them, and can also be written as 2TP / (2TP + FP + FN), which shows that true negatives never enter the formula.
The harmonic mean is chosen deliberately. Unlike the arithmetic mean, it is dominated by the smaller of the two values, so a model cannot score well by maximizing one metric and neglecting the other. The table below illustrates the effect.
| Precision | Recall | Arithmetic mean | F1 score |
|---|---|---|---|
| 0.90 | 0.90 | 0.90 | 0.90 |
| 0.95 | 0.50 | 0.73 | 0.66 |
| 1.00 | 0.10 | 0.55 | 0.18 |
| 0.50 | 0.50 | 0.50 | 0.50 |
| 0.20 | 0.95 | 0.58 | 0.33 |
A classifier that predicts positive for every example has recall of 1.0 and precision equal to the positive class rate. On a dataset with 5 percent positives, that trivial model scores an F1 of about 0.10, which is a useful baseline to beat when reporting results.
Variants: F-beta, macro, micro and weighted F1
F1 is the special case of the F-beta score, (1 + beta^2) * P * R / (beta^2 * P + R), in which precision and recall are weighted equally. Setting beta above 1 favors recall, and setting it below 1 favors precision. F2 is common in screening tasks where missed cases are costly; F0.5 is common where false alarms are expensive.
In multi-class and multi-label problems, per-class F1 values must be averaged, and the averaging method changes the result considerably.
| Averaging method | How it is computed | When to use it |
|---|---|---|
| Macro F1 | Unweighted mean of per-class F1 | Every class matters equally, including rare ones |
| Micro F1 | F1 from pooled TP, FP and FN | Overall performance per example |
| Weighted F1 | Per-class F1 weighted by class frequency | Reporting that reflects class distribution |
| Samples F1 | F1 per example, then averaged | Multi-label tasks such as tagging |
For single-label multi-class classification, micro F1 equals accuracy, which surprises many practitioners. Reports should therefore always state the averaging method, because macro and micro F1 can differ by tens of points on skewed data.
F1 compared with other evaluation metrics
F1 is a threshold-dependent point metric: it evaluates one specific decision threshold. Other metrics summarize behavior across thresholds or include true negatives, and the right choice depends on what the evaluation dataset and the application need.
| Metric | Uses true negatives | Threshold-free | Best use |
|---|---|---|---|
| F1 score | No | No | Imbalanced tasks with a fixed decision rule |
| Accuracy | Yes | No | Balanced classes, equal error costs |
| Precision | No | No | Cost of false alarms is high |
| Recall | No | No | Cost of misses is high |
| ROC AUC | Yes | Yes | Ranking quality across thresholds |
| PR AUC | No | Yes | Ranking quality on rare positives |
| Matthews correlation | Yes | No | Balanced single number for binary tasks |
F1 is also widely used beyond classic classifiers. Token-level F1 measures overlap between predicted and reference answers in extractive question answering, and entity-level F1 is the standard score for named entity recognition. These definitions share the formula but count matches differently, so scores from different benchmarks are not directly comparable.
Using F1 in practice
Most classifiers output a probability, and F1 depends on the threshold that converts it into a label. The default of 0.5 is rarely optimal on imbalanced data. Teams typically sweep thresholds on a validation set, pick the one that maximizes F1 or meets a business constraint, and then report F1 on a separate test set to avoid optimistic bias.
| Situation | Recommended metric | Reason |
|---|---|---|
| Fraud or defect detection | F1 or PR AUC | Positives are rare |
| Medical screening | F2 or recall at fixed precision | Missed cases are costly |
| Spam filtering | F0.5 or precision | Blocking legitimate mail is costly |
| Many classes of unequal size | Macro F1 with per-class report | Rare classes stay visible |
| Comparing models before deployment | PR AUC plus F1 at chosen threshold | Separates ranking from decision |
Common mistakes and limitations
- Ignoring unequal costs. F1 weights false positives and false negatives equally, which rarely matches real costs.
- Comparing F1 across datasets. The score depends on the positive class rate, so the same model scores differently on different data.
- Averaging fold F1 values carelessly. The mean of per-fold F1 differs from F1 computed on pooled predictions.
- Undefined values. When a class is never predicted, precision is undefined, and libraries silently return 0.
- Choosing the threshold on test data. This inflates the reported score.
F1 also says nothing about calibration. Two models with identical F1 can produce very different probability estimates, which matters when scores feed downstream decisions. For a complete picture, F1 should be reported together with precision, recall and the confusion matrix it was derived from.
The idea in brief
Think of a metal detector on a beach. A good detector finds most of the buried coins and does not beep at every bottle cap. The F1 score rates how well a model does both at once.
If the detector beeps at everything, it finds every coin but wastes your time. If it beeps only when it is certain, it misses most coins. F1 stays high only when both finding and avoiding false alarms are good, which makes it a fair single grade for tasks where the interesting cases are rare.
A practical scenario
A manufacturer trains a vision model to flag defective circuit boards. Only about 3 percent of boards are defective, so a model that passes every board would score 97 percent accuracy while catching nothing.
The team evaluates with F1 instead. At the default threshold of 0.5, precision is 0.92 but recall is only 0.61, giving an F1 of about 0.73. By lowering the threshold to 0.3 on the validation set, recall rises to 0.84 and precision falls to 0.81, which lifts F1 to about 0.82. Because a missed defect costs more than an extra manual inspection, the team finally reports F2 as well and chooses the threshold that keeps recall above 0.85, accepting a modest increase in manual checks.