← AI Terminology

F1 Score

The F1 score is the harmonic mean of Precision and Recall — a single metric that balances the tradeoff between avoiding false positives (precision) and avoiding false negatives (recall).

F1 = 2 × (Precision × Recall) / (Precision + Recall).
Why It Matters in AI
Accuracy is misleading on imbalanced datasets; precision alone rewards being selective; recall alone rewards catching everything. F1 penalises both extremes: a model that catches all positives but raises constant false alarms gets punished; so does one that's precise but misses most true positives. It's the standard metric for information retrieval, NER, object detection, and any binary classification with class imbalance.
Key Points
Aspect Description
F-beta Fβ = (1+β²) × (P×R) / (β²×P + R) — β>1 weights recall higher; β<1 weights precision higher
Recall Of all actual positives, what fraction did we catch: TP / (TP + FN)
Precision Of all predicted positives, what fraction are truly positive: TP / (TP + FP)
Limitation Ignores true negatives — not meaningful when TN matters (use MCC or AUC instead)
Harmonic mean More conservative than arithmetic mean — punishes large imbalances between P and R
Macro vs micro Macro: average F1 per class. Micro: aggregate TP/FP/FN across all classes — treats all instances equally
Simple Analogy
A search engine that returns 10 results: if 9 are relevant (precision = 90%) but there were 100 relevant documents and it missed 91 (recall = 9%), its F1 is poor. A good search engine finds most relevant documents (high recall) while not burying them in irrelevant results (high precision) — F1 rewards that balance.
Common Usage Examples
  • sklearn.metrics.f1_score(y_true, y_pred, average='weighted') — weighted by class support
  • NER evaluation: entity-level F1 — the standard metric for CoNLL, OntoNotes benchmarks
  • Object detection: F1 derived from precision-recall curve at a given IoU threshold
  • GLUE benchmark: F1 used for QA tasks (SQuAD), NER, and other information extraction tasks
  • classification_report(y_true, y_pred) — prints precision, recall, F1 per class and macro averages
Summary
In short: F1 score balances precision and recall into one number — the right metric when you need to minimise both false positives and false negatives simultaneously.