F1 Score Calculator
Get the F1 score, precision, recall and F-beta from a confusion matrix, with the working shown.
Enter your numbers to see the result.
What is the F1 score?
The F1 score is a single number that summarizes how well a classification model finds the positive class. It combines two other measures:
- Precision: of everything the model labeled positive, how much was really positive. Precision = TP / (TP + FP).
- Recall (also called sensitivity or true positive rate): of all real positives, how many the model found. Recall = TP / (TP + FN).
F1 is the harmonic mean of the two. It ranges from 0 (no true positives) to 1 (perfect precision and recall), and it is high only when both precision and recall are high.
How to calculate the F1 score
You can compute it from precision and recall, or directly from the confusion matrix counts:
F1 = 2·TP / (2·TP + FP + FN)
Worked example. A spam filter checks 100 emails. It flags 50 as spam, and 45 of those really are spam (TP = 45, FP = 5). It misses 15 spam emails (FN = 15). Then:
- Precision = 45 / (45 + 5) = 0.90
- Recall = 45 / (45 + 15) = 0.75
- F1 = 2 · 0.90 · 0.75 / (0.90 + 0.75) = 1.35 / 1.65 ≈ 0.818
The direct formula gives the same answer: 2·45 / (2·45 + 5 + 15) = 90 / 110 ≈ 0.818. These are the default values in the calculator above.
Why a harmonic mean?
The harmonic mean is pulled towards the smaller of the two numbers, so a model cannot hide poor recall behind excellent precision, or the other way round. A model with precision 1.0 and recall 0.1 has an arithmetic mean of 0.55, which sounds respectable, but its F1 is only 2 · 1.0 · 0.1 / 1.1 ≈ 0.18, which reflects how many positives it misses.
F1 score vs accuracy
Accuracy, (TP + TN) / total, can be misleading when one class is rare. Imagine 1,000 transactions of which 10 are fraudulent. A model that never flags anything is 99% accurate, yet it catches no fraud: TP = 0, so recall and F1 are both 0. F1 ignores true negatives and focuses on the positive class, which is why it is popular for imbalanced problems such as fraud detection, information retrieval and medical screening.
The flip side is that F1 says nothing about how well negatives are handled. If both classes matter, report it together with a measure that uses all four cells, such as the Matthews correlation coefficient (MCC) or balanced accuracy. Enter TN in the calculator to see accuracy, specificity and MCC.
F-beta: weighting precision or recall
F1 treats precision and recall as equally important. The general F-beta score lets you choose:
- β > 1 favors recall. F2 is common when missing a positive is costly, as in disease screening.
- β < 1 favors precision. F0.5 suits cases where false alarms are costly, such as spam filtering.
For the spam example above, F2 ≈ 0.776 and F0.5 ≈ 0.865. Set β in the calculator to compare.
F1 for multi-class problems
With more than two classes, compute precision, recall and F1 for each class in a one-vs-rest way, then average:
| Average | How it works | Use it when |
|---|---|---|
| Macro | Plain mean of the per-class F1 scores. | Every class matters equally, including rare ones. |
| Weighted | Mean of per-class F1, weighted by each class’s number of true instances (support). | You want an overall figure that reflects class frequencies. |
| Micro | Adds up TP, FP and FN over all classes, then applies the F1 formula once. | You care about overall per-item performance. For single-label tasks it equals accuracy. |
Calculating F1 in Python
In scikit-learn, f1_score handles binary and multi-class cases:
from sklearn.metrics import f1_score, fbeta_score
y_true = [1, 0, 1, 1, 0, 1]
y_pred = [1, 0, 0, 1, 1, 1]
f1_score(y_true, y_pred) # binary F1 = 0.75
fbeta_score(y_true, y_pred, beta=2) # F2 = 0.75
f1_score(y_true, y_pred, average="macro")
In this small example TP = 3, FP = 1 and FN = 1, so precision and recall are both 0.75 and every F-beta equals 0.75. If a class has no predicted or true positives, F1 is undefined; scikit-learn returns 0 by default and lets you change this with the zero_division argument.
Limitations to keep in mind
- F1 depends on the decision threshold. Changing the threshold trades precision for recall, so compare models at sensible thresholds, or look at the precision–recall curve.
- It ignores true negatives, as described above.
- It is not symmetric: swapping which class you call “positive” changes the score.
- Averages across classes can hide a class that performs badly, so check per-class scores too.
Frequently asked questions
What is a good F1 score?
There is no universal cut-off: closer to 1 is better, but what counts as good depends on the task. Always compare with a simple baseline. A model that labels everything as positive gets F1 = 2p / (1 + p), where p is the share of positive cases, so with 10% positives that baseline already scores about 0.18.
Can the F1 score be higher than accuracy?
Yes. F1 ignores true negatives, so it can exceed accuracy when there are few of them. With TP = 80, FP = 10, FN = 10 and TN = 0, accuracy is 0.80 but F1 is 160 / 180 ≈ 0.89.
What does an F1 score of 0 mean?
It means the model found no true positives: TP = 0 while there were positive cases or positive predictions. Precision and recall are then both 0 (or precision is undefined if the model never predicted the positive class).
Is the F1 score the same as the Dice coefficient?
Yes. For binary labels, F1 = 2·TP / (2·TP + FP + FN), which is exactly the Sørensen–Dice coefficient between the set of predicted positives and the set of actual positives. Image segmentation papers usually call it Dice.
Why does F1 ignore true negatives?
By design it measures how well the positive class is found, which is what matters in tasks like search, fraud or disease detection. If true negatives matter too, also report the Matthews correlation coefficient (MCC) or balanced accuracy; the calculator shows MCC when you enter TN.
What is the difference between macro and micro F1?
Macro F1 computes F1 for each class and takes the plain average, so rare classes count as much as common ones. Micro F1 pools all TP, FP and FN first; for single-label multi-class problems it equals accuracy. Weighted F1 averages per-class F1 weighted by each class’s number of true instances.
Last reviewed 27 November 2026 · Report an error