AppsGuidesAI DictionarySmall FixesOn RecordAboutFollow the lab

Accuracy and F1 score

Also called f1 score, accuracy

Accuracy is the share of a model's answers that are right. F1 score checks whether it also catches the rare cases that matter, without crying wolf.

In plain words

Accuracy is the score everyone understands: out of 100 answers, how many were right? If a model gets 93 right, it is 93% accurate.

The trouble starts when one answer is rare. Say only 5 in every 100 card payments are fraud. A lazy model that always says "safe" is right 95 times out of 100. That is 95% accuracy, and it has not caught a single fraud.

The F1 score handles this far better. It ignores the easy correct "no" answers and focuses on the rare class. It asks two questions: when the model raised an alarm, was it right? And of all the real cases, how many did it catch? Then it combines both into one number from 0 to 1.

The lazy model scores an F1 of 0. A model that catches 4 of the 5 frauds, with 6 false alarms, is slightly less accurate at 93%, but its F1 is 0.53. That is the model you actually want.

Everyday example

The exam that is mostly true

A true or false test has 100 questions, and 95 of the answers are "true". A student who writes "true" for everything without reading scores 95%. The marks look brilliant, but the student learned nothing. A teacher who wants to know if anyone read the chapter would look only at the 5 tricky "false" questions. F1 is that teacher.

Where the example breaks: A teacher can read the answers and judge understanding. F1 only counts hits, misses and false alarms on the rare class, and it ignores the correct "no" answers entirely, which sometimes matter too.

Go deeper

How it actually works

Both are built from the four counts of a confusion matrix: true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN).

  1. Accuracy

    accuracy = (TP + TN) ÷ (TP + TN + FP + FN): every correct answer over every answer. Google's crash course advises using it as a rough guide for balanced data and avoiding it when one class is rare.

  2. F1: the harmonic mean of precision and recall

    Precision is TP ÷ (TP + FP); recall is TP ÷ (TP + FN). F1 = 2 × precision × recall ÷ (precision + recall), which simplifies to 2TP ÷ (2TP + FP + FN). Notice TN does not appear at all.

  3. Why a harmonic mean

    A plain average would let one strong number hide a weak one. With precision 1.0 and recall 0.1, the plain average is 0.55, but F1 is about 0.18. F1 is only high when both are high.

  4. Weighting with F-beta

    If missing a case is worse than a false alarm, use F2, which weights recall more heavily. If false alarms are worse, F0.5 leans the other way. F1 is the even split.

  5. Many classes: macro and micro

    With more than two classes, F1 is worked out per class, then averaged. Macro F1 gives every class equal say, so rare classes count as much as common ones. Micro F1 pools all the counts first. Weighted F1 averages by how common each class is.

Range
Both run from 0 to 1 (or 0% to 100%); 1 is perfect
In the picture
100 payments, 5 fraud. Always "safe": accuracy 95%, F1 0. Model B: accuracy 93%, precision 0.4, recall 0.8, F1 0.53
Origin of F
Based on C. J. van Rijsbergen's 1979 effectiveness measure; named F-measure at the MUC-4 conference in 1992
Main criticism
F1 ignores true negatives and weights precision and recall equally, even when their costs differ

Questions people ask

What is a good F1 score?

There is no universal cut-off. It depends on the task and the baseline. An F1 of 0.6 could be excellent for a hard medical problem and poor for spam filtering. Compare against a simple baseline and against other models on the same test set.

Is F1 score better than accuracy?

For imbalanced data, usually yes, because accuracy rewards guessing the common class. When classes are roughly balanced and both kinds of mistake cost the same, accuracy is simpler and fine. Many teams report both, plus precision and recall.

Why is accuracy misleading?

When one outcome is rare, a model can score highly by always predicting the common outcome. Google's course gives the example of a class that appears 1% of the time: predicting "no" every time scores 99% accuracy while being useless.

Can accuracy be high and F1 low?

Yes, and it is a classic warning sign. It happens when the positive class is rare and the model mostly predicts the negative class. In our picture, the always "safe" model has 95% accuracy and an F1 of 0.

What is the difference between F1 score and the precision-recall trade-off?

Precision and recall often pull against each other as you change a model's cut-off. F1 is one number that summarises a single point on that trade-off, at one chosen cut-off. See precision and recall for the full picture.

Was this clear?

1 is confusing, 5 is crystal clear. One tap, no account needed.

Spotted something wrong, or know a better example? Suggest a change

Further reading