Data Science & ML
Intermediate

F1 Score

Harmonic mean of precision and recall.

Formula

F1=2⋅Precision⋅RecallPrecision+RecallF_1 = 2\cdot\frac{Precision \cdot Recall}{Precision + Recall}

Live Calculator

Members

Variables

PrecisionPositive predictive value
RecallSensitivity

Example

P=0.8, R=0.6: F1 = 2(0.48/1.4) = 0.686

How it works

The F1 score combines precision and recall into a single number so you can judge a classifier that must avoid both false alarms and missed positives. It uses the harmonic mean, which is stricter than the arithmetic mean: if either precision or recall is low, the F1 score is pulled down sharply, reflecting the idea that a model is only as good as its weaker side. This makes it useful when the positive class is important and you want balance rather than a score that looks good because one metric is excellent while the other is poor.

When to use it

Use F1 score in classification tasks with imbalanced classes, such as fraud detection, medical screening, spam detection, or information retrieval. It is especially helpful when false positives and false negatives both matter and you need one summary metric for comparing models.

Worked example, step by step

Suppose a model has precision = 0.75 and recall = 0.50. Step 1: Add the two values: 0.75 + 0.50 = 1.25 Step 2: Multiply precision and recall: 0.75 × 0.50 = 0.375 Step 3: Plug into the formula: F1 = 2 × (0.375 / 1.25) Step 4: Divide: 0.375 / 1.25 = 0.30 Step 5: Multiply by 2: F1 = 0.60 Final answer: the F1 score is 0.60

Common mistakes to avoid

  • Using accuracy instead of precision or recall in the formula
  • Forgetting that F1 only makes sense for the positive class in binary classification unless averaged carefully for multiclass problems
  • Thinking a high F1 can happen when one of precision or recall is very low

Did You Know?

The harmonic mean punishes extreme imbalance between precision and recall.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026