# F1 score

> Canonical: https://skillalmanac.com/glossary/f1-score | Last verified: 2026-11-24 | Index status: index-eligible

The F1 score is a single number that combines a classifier's precision and recall as their harmonic mean. It is at best 1 and at worst 0, and it gives precision and recall equal weight.

Also called: F1, F-score, F-measure, f1-score, f1 score formula, f1 score machine learning.

## In plain language

A classifier can fail in two ways: it can miss real cases, or it can raise false alarms. Recall tracks the first, precision the second. The F1 score blends them into one number so you can compare models quickly. Think of a spam filter: if it flags almost everything it catches all the spam but buries good mail, and F1 reflects that cost. The limits: one number hides which of the two mistakes is happening, it treats both as equally important when yours may not be, and its formula contains no count of correctly rejected cases. When TP, FP and FN are all zero, F1 is undefined; scikit-learn’s zero_division setting controls the returned value.

## Technical definition

For a specified class, F1 is 2TP/(2TP+FP+FN), equivalent to the harmonic mean of precision and recall when the ratios are defined. True negatives do not enter. Micro F1 pools counts; macro and support-weighted F1 average per-label F1 values; samples averaging applies per instance in multilabel tasks. Report label selection and undefined-case handling.

## How it shows up when you use agents

F1 shows up when you ask an agent to evaluate a classifier and it prints a short report: precision, recall, F1. Google's crash course gives precision as TP over TP plus FP, recall as TP over TP plus FN, and F1 as 2 times precision times recall over their sum. An agent may also report several F1 values, which can confuse people.

What breaks when it is misunderstood. With more than two classes, scikit-learn offers micro, macro and weighted averages, and they can give different answers on the same predictions. Its documentation notes that a weighted average can produce a score not between precision and recall. If a report says only "F1" without the average, the number is hard to interpret. See [Classification](/glossary/classification) and [Ground truth](/glossary/ground-truth).

Next actions. Ask which average was used and which class counts as positive. Print precision and recall beside F1. Check the test split with [split-leakage-check](/skills/skill-almanac/split-leakage-check) before trusting any of them.

## Worked example (illustrative)

For actual labels [0,0,0,1] and predictions [0,0,1,1], scikit-learn gives macro F1 about 0.7333. The harmonic mean of macro precision and macro recall is instead about 0.7895. Macro F1 averages the per-class F1 values; it is not generally computed from the already-averaged precision and recall. These are calculated synthetic labels, not a model-quality result.

## Common confusions

- **F1 versus accuracy.** Accuracy counts all correct predictions, including true negatives. The F1 formula has no true-negative term.
- **F1 versus the F-beta family.** F1 weights precision and recall equally. Other beta values weight them differently.
- **Micro versus macro averaging.** Macro is the unweighted mean of per-class F1 scores, giving each included class equal weight. Micro counts totals globally. scikit-learn notes that micro-averaging over all labels in multiclass gives the same value as accuracy.
- **Myth.** A score of 0 means the model is broken. scikit-learn also returns 0.0 by default when the score is undefined, for example when a class is absent from both labels and predictions.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A check of train, validation and test files for duplicates, shared groups, time and label leakage, printed as JSON.

Why it exercises the concept: Check the labelled evaluation data for leakage before computing F1. This skill checks the data; a separate metric implementation computes the score.

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.

Why it exercises the concept: F1 is computed against labelled examples. If an LLM feature assigns labels, this skill helps build and check that labelled set. It does not compute F1 itself.

### [sample-size-calculator](https://skillalmanac.com/skills/skill-almanac/sample-size-calculator)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Computes the minimum number of subjects per group for a planned comparison of two proportions, two means, or one mean, using the normal approximation.

Why it exercises the concept: A contrast case: it plans how many subjects a comparison needs, while F1 scores a classifier on a test set. It does not give the size of a test set needed to trust an F1 figure.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Claude Code's overview page describes it as an agentic coding tool that reads your codebase, edits files, runs commands, and integrates with your development tools.

Why it exercises the concept: A coding agent can call scikit-learn's f1_score on small label lists and show how the average option changes the result on multiclass data.

## Related terms

- [Classification](https://skillalmanac.com/glossary/classification.md)
- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Ground truth](https://skillalmanac.com/glossary/ground-truth.md)
- [Logistic regression](https://skillalmanac.com/glossary/logistic-regression.md)

## Sources

- [sklearn.metrics.f1_score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html), scikit-learn (accessed 2026-11-24)
- [Classification: Accuracy, recall, precision and related metrics](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall), Google for Developers (Machine Learning Crash Course) (accessed 2026-11-24)
- [3.4. Metrics and scoring: quantifying the quality of predictions (F-measure)](https://scikit-learn.org/stable/modules/model_evaluation.html), scikit-learn (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
