What is the AI F1 score?
The F1 score is the harmonic mean of a classification model's precision and recall, combining them into one number that is more meaningful than accuracy when classes are imbalanced.
Unlike accuracy, which counts all correct predictions and can overlook rare classes, F1 focuses on the positive class of interest. Precision measures how many positive predictions are truly positive, recall how many true positives are caught.
- Topic
- Evaluation and quality
- Also known as
- F-measure, F1 measure
How the AI F1 score works
- Predictions are counted in a confusion matrix as true positives, false positives and false negatives.
- Precision = true positives / (true positives + false positives); recall = true positives / (true positives + false negatives).
- F1 = 2 × precision × recall / (precision + recall); the harmonic mean stays close to the lower of the two.
- For multi-class tasks F1 is computed per class and averaged; the macro average weights each class equally.
In more detail
Micro, macro and weighted F1
Multi-class and multi-label tasks aggregate per-class scores differently. Macro-F1 averages every class equally (highlighting failure on rare classes), Weighted-F1 weights each class by its sample count and Micro-F1 sums global TP, FP and FN counts across all classes, meaning in single-label multi-class classification, Micro-F1 equals overall accuracy.
The F-beta score and asymmetric error costs
When false negatives and false positives carry unequal costs, the F-beta score is used; the beta coefficient sets how many times more weight recall gets than precision, with a beta of 1 giving F1. A beta of 2 (F2 score) weights recall more heavily for medical screening or fraud detection, whereas a beta of 0.5 (F0.5 score) favours precision to avoid costly false alarms.
Decision thresholds, threshold tuning and excluded true negatives
F1 is computed on hard binary labels at a single probability threshold (often 0.5 by default). Tuning that cutoff on a validation set can substantially raise F1 on imbalanced tasks without retraining, while threshold-free Precision-Recall AUC (PR-AUC) evaluates performance across all possible thresholds. Also note that F1 completely ignores true negatives (TN).
Token-level F1 in generative AI and entity extraction
In modern NLP, RAG and information-extraction benchmarks (such as SQuAD or named-entity recognition), token-level F1 measures partial word or token overlap between a generated answer span and the reference answer, complementing strict Exact Match (EM) metrics.
Commonly confused terms
| Term | How it differs |
|---|---|
| ROC-AUC and PR-AUC | ROC-AUC evaluates ranking performance across all classification thresholds using TPR and FPR, which can look overly optimistic under severe class imbalance; F1 evaluates a single fixed threshold and PR-AUC summarises precision-recall across thresholds. |
| Matthews correlation coefficient (MCC) | Unlike F1, which ignores true negatives, the Matthews Correlation Coefficient (MCC) uses all four cells of the confusion matrix (TP, FP, TN, FN) and yields a reliable score even when both positive and negative classes matter equally. |
Why the AI F1 score matters for on-premises AI
In in-house classification the event of interest is often rare: a fraudulent transaction, a faulty part, a complaint email. If 10 of 1,000 records are positive, a model calling everything “negative” scores 990 / 1,000 = 99 per cent accuracy yet an F1 of zero, catching not one positive. On imbalanced tasks F1, or precision with recall, is therefore tracked. F1 weighs both error types equally; when false negatives cost more, measures weighting recall are preferred.
A manufacturer picks its faulty part detection model for quality control images by F1 rather than accuracy; with few faulty parts, every candidate's accuracy is high while F1 shows the difference.
Common questions
Why does the F1 score use the harmonic mean?
The harmonic mean stays close to the lower value. If precision or recall is very low, F1 is low too, so one high value cannot make a poor model look good.
When is the F1 score misleading?
When the two error types cost very different amounts. F1 counts false positives and false negatives equally; if one costs more, weighted measures or precision and recall directly are tracked.
Related terms
Sources
- A systematic analysis of performance measures for classification tasks, 2009
- MUC-4 Evaluation Metrics, 1992
In the glossary: Glossary, E to L