ThisCalculator

Everyday

F1 Score Calculation Formula & Example

Updated · Standard formula, shown below

F1 Score 0.870
Precision
0.833
Result
Recall
0.909
Result
True Positives
50
You entered

The F1 score is the harmonic mean of precision and recall, calculated as F1 = 2 × (precision × recall) / (precision + recall). You enter the counts of true positives, false positives, and false negatives from a classification model, and the calculator returns the F1 score on a 0 to 1 scale, where 1 is perfect precision and recall.

Formula

The F1 score formula in words: F1 = 2 × (Precision × Recall) / (Precision + Recall).

Where:

  • Precision = True Positives / (True Positives + False Positives) — of all items the model labeled positive, how many were actually positive.
  • Recall (also called Sensitivity) = True Positives / (True Positives + False Negatives) — of all actual positive items, how many the model caught.
  • True Positives (TP): correctly predicted positive cases.
  • False Positives (FP): negative cases incorrectly predicted as positive.
  • False Negatives (FN): positive cases incorrectly predicted as negative.

The F1 score ranges from 0 to 1. A score of 1 means both precision and recall are perfect; 0 means either is 0. Because it is a harmonic mean, the F1 score is always closer to the smaller of precision and recall, so it penalizes a large imbalance between them.

Worked Example

Using the default values from the calculator: TP = 50, FP = 10, FN = 5.

  1. Precision = 50 / (50 + 10) = 50 / 60 = 0.8333
  2. Recall = 50 / (50 + 5) = 50 / 55 = 0.9091
  3. F1 = 2 × (0.8333 × 0.9091) / (0.8333 + 0.9091) = 2 × 0.7576 / 1.7424 = 1.5152 / 1.7424 = 0.8696

The calculator rounds to 3 decimals, giving an F1 score of 0.870. The precision is 0.833 and recall is 0.909. Notice the F1 score is closer to precision (0.833) than to recall (0.909), because the harmonic mean gives more weight to the lower value.

Why Use F1 Instead of Accuracy?

Accuracy (correct predictions / total predictions) can be misleading when classes are imbalanced. For example, if 95% of your data is negative and 5% positive, a model that predicts “negative” for everything gets 95% accuracy but catches zero positives. The F1 score captures both false positives and false negatives, so it gives a more honest picture when you care about the positive class.

F1 is especially common in:

  • Information retrieval (search engines, document classification)
  • Medical diagnostics (detecting diseases)
  • Fraud detection
  • Spam filtering
  • Natural language processing tasks like named entity recognition

In these fields, both missing a positive (false negative) and falsely flagging a negative (false positive) have real costs, and F1 balances them.

How to Choose Between Precision, Recall, and F1

Your choice depends on the cost of each type of error:

  • Prioritize Recall when missing a positive is worse than a false alarm. Example: cancer screening — you want to catch every possible case, even if it means more follow-up tests.
  • Prioritize Precision when false positives are more costly. Example: spam filter — you’d rather let a spam email through than block an important legitimate email.
  • Use F1 when both error types matter equally, or when you want a single balanced metric.

For imbalanced datasets, F1 is often more informative than accuracy. However, if your dataset is balanced and errors are symmetric, accuracy may be simpler and easier to interpret.

Common Mistakes and Misconceptions

  • Using the arithmetic mean instead of harmonic mean. The harmonic mean is always lower than or equal to the arithmetic mean. If you average precision and recall arithmetically, you overestimate performance when they differ.
  • Confusing precision with recall. A common memory aid: precision asks “of what we predicted positive, how many were right?”; recall asks “of all actual positives, how many did we catch?”
  • Ignoring true negatives. F1 does not use true negatives at all, which is fine when you only care about the positive class, but it means F1 is not suitable for problems where true negatives matter (e.g., a test that should correctly identify negatives).
  • Rounding too early. In the worked example, if you round precision to 0.833 and recall to 0.909 before computing F1, you get 0.869, not 0.870. Always keep more decimal places during intermediate steps.
  • Using F1 on multi-class problems incorrectly. For multi-class, you typically compute F1 per class (one-vs-rest) and then average (macro) or weight by class size (weighted). The simple formula above applies to binary classification only.

Limitations of the F1 Score

F1 assumes precision and recall are equally important. If that’s not true, you should use the F-beta score, which weights recall by a factor beta. For example, F2 weights recall twice as much as precision; F0.5 weights precision twice as much.

F1 also ignores true negatives, so it can give a high score even if the model wrongly predicts many negatives as positive—if the positive class is rare, a model that predicts everything positive might still get a moderate F1. Always examine the confusion matrix alongside F1.

Finally, F1 is not directly interpretable as a probability. A score of 0.87 does not mean 87% of predictions are correct; it is a harmonic mean, not a percentage of correct predictions.

Frequently Asked Questions

What is the difference between F1 and F-beta?

F1 is a special case of F-beta where beta = 1, giving equal weight to precision and recall. F-beta lets you adjust the importance: beta > 1 favors recall, beta < 1 favors precision. The formula is F-beta = (1 + beta²) × (precision × recall) / (beta² × precision + recall).

Can F1 be greater than 1?

No. Precision and recall are each between 0 and 1, so their harmonic mean is also between 0 and 1. The maximum is 1, achieved only when both precision and recall are exactly 1.

What does an F1 score of 0 mean?

It means either precision or recall is 0. This happens when there are no true positives—either the model predicted nothing positive (recall = 0) or every positive prediction was wrong (precision = 0).

Should I use F1 for imbalanced datasets?

Yes, F1 is often better than accuracy for imbalanced data because it focuses on the positive class. However, if the positive class is extremely rare, consider using precision-recall curves or the area under the precision-recall curve, which give a fuller picture across thresholds.

How do I calculate F1 for multi-class classification?

You compute F1 for each class separately, treating that class as positive and all others as negative. Then you can average the F1 scores (macro-F1, treating classes equally) or weight them by the number of true instances (weighted-F1). Some implementations also offer micro-F1, which pools all TP/FP/FN across classes before computing F1.

Is F1 the same as the Dice coefficient?

Yes, in binary classification, the F1 score is mathematically identical to the Sørensen–Dice coefficient, which is commonly used in image segmentation. Both are 2 × TP / (2 × TP + FP + FN). The names come from different fields, but the formula is the same.

Related

Formula used
in tp | True Positives | - | 50 | 0
in fp | False Positives | - | 10 | 0
in fn | False Negatives | - | 5 | 0
out f1 | F1 Score | - | 2 * (tp / (tp + fp)) * (tp / (tp + fn)) / ((tp / (tp + fp)) + (tp / (tp + fn))) | 3
out precision | Precision | - | tp / (tp + fp) | 3
out recall | Recall | - | tp / (tp + fn) | 3

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.