The F1 score combines precision and recall into one metric. Learn the F1 score formula, see a worked example, and know when to use it.

Updated August 2026
The F1 score is a classification metric that combines precision and recall into one number. It is the harmonic mean of those two measures, so a high F1 score requires both few false positives and few false negatives. It is useful when the positive class matters and accuracy alone could be misleading.
The F1 score formula is:
F1 = 2 × (precision × recall) / (precision + recall)
Precision is TP / (TP + FP): of the items predicted positive, how many were correct? Recall is TP / (TP + FN): of the truly positive items, how many did the model find?
This is the standard F1 definition used by scikit-learn. Its implementation also documents how zero-division cases are handled when a model makes no positive predictions.
The equivalent formula makes the error tradeoff clear:
F1 = 2TP / (2TP + FP + FN)
Start with a confusion matrix. Suppose a fraud model identifies 80 fraudulent transactions correctly, flags 20 legitimate transactions by mistake, and misses 20 fraudulent transactions. Precision is 80 / (80 + 20) = 0.80; recall is 80 / (80 + 20) = 0.80; the F1 score is 0.80.
If precision is 0.90 and recall is 0.50, the F1 score is 0.64, not 0.70. The harmonic mean pulls the result toward the weaker measure. That is the point: a model cannot hide poor recall behind excellent precision, or the reverse.
| Measure | Formula | Example result |
|---|---|---|
| Precision | TP / (TP + FP) | 0.80 |
| Recall | TP / (TP + FN) | 0.80 |
| F1 score | 2PR / (P + R) | 0.80 |

An F1 score ranges from 0 to 1, where 1 means perfect precision and recall for the evaluated class. There is no universal threshold for a "good" F1 score. Compare it with a baseline, the cost of errors, and the score on the same held-out data and decision threshold.
A spam filter may value precision because wrongly hiding legitimate email is costly. A safety alert may value recall because missing a true event is costly. If one error type matters more, use an F-beta score instead of treating F1 as the final decision rule.
F1 is often more useful than accuracy when classes are imbalanced. A model that labels every transaction legitimate could look accurate when fraud is rare, yet find no fraud at all. F1 focuses on the positive class through precision and recall.
Accuracy still matters when correct predictions across every class have similar value. Report a confusion matrix alongside F1 so readers can see the error pattern rather than relying on one summary number.
For multi-class classification, macro F1 gives each class equal weight, micro F1 aggregates all decisions before calculating the score, and weighted F1 averages class-level F1 scores by support. These averaging modes follow scikit-learn's documented definitions. Macro F1 is useful when small classes matter, while weighted F1 can obscure weak performance on rare classes.
F1 is useful when a classifier must balance two costly mistakes. The right balance depends on the decision the model supports.
| Use case | Positive class | Error tradeoff |
|---|---|---|
| Fraud detection | Fraudulent transaction | Missing fraud can create direct loss, while excessive false alerts send legitimate customers into review. |
| Medical screening | Patient likely to have the condition | High recall can be important because a missed case may delay care. Precision still matters because false positives can trigger unnecessary follow-up. |
| Spam filtering | Spam message | Low precision can hide legitimate messages. Teams may accept lower recall to avoid putting important email in a spam folder. |
| Content moderation | Policy-violating content | Missed violations create safety risk, while false positives can wrongly remove valid speech or creator content. |
These examples also show why F1 is not the final decision rule. A fraud model and a medical screener can have the same F1 score while creating very different operational outcomes. Review the confusion matrix, the threshold, and the cost of each error alongside F1.
The peer-reviewed metric comparison includes a real colon-cancer gene-expression classification scenario alongside synthetic confusion-matrix cases. It is a useful example of why the chosen metric can change how a model's performance is interpreted.
F1 is most useful when it is part of an evaluation set, not the only number on a dashboard. Start with the question the classifier is meant to answer and declare the positive class. That sounds basic, but it prevents a common mistake: reporting a high F1 score without explaining which event the score measures.
Then compare F1 across a fixed test set, model version, and decision threshold. If the test distribution shifts, keep the old benchmark and add a new one rather than treating the results as directly comparable. A classification problem can also warrant per-segment reporting. A fraud detector that performs well overall may still miss a meaningful subgroup.
For a broader framing of labels, thresholds, and error types, see Telnyx's AI classification explainer. Pair it with the entropy in machine learning guide when you need to explain uncertainty and information rather than only a pass or fail prediction.
Many classifiers output a score or probability, then use a threshold to turn that value into a class label. Changing the threshold changes precision, recall, and F1. A default threshold of 0.5 is a convention, not an optimized business decision.
Evaluate candidate thresholds on validation data. Google's classification guide shows how changing a classification threshold shifts precision and recall in opposite directions. Calculate F1 at each candidate threshold, then inspect whether the underlying false-positive and false-negative counts are acceptable for the workflow.
For example, an account-review queue may have limited capacity. Raising the threshold might improve precision, which means fewer unnecessary reviews, while reducing recall. A security alert may choose the reverse. F1 can help compare thresholds, but it cannot decide the cost tradeoff on its own.
The first mistake is calculating F1 on training data. The score should be reported on held-out data that was not used to fit the model or choose the threshold. The second is collapsing several classes or segments into one average without showing the individual results.
Another mistake is treating F1 as proof that the probability estimates are calibrated. F1 evaluates decisions after a threshold. Calibration asks whether predictions described as 80% likely occur about 80% of the time. A model can have a useful F1 score and poorly calibrated probabilities.
F1 also ignores true negatives. A peer-reviewed comparison tested F1, accuracy, and the Matthews correlation coefficient across 6 synthetic confusion-matrix cases and a genomics example. MCC was the only measure that identified the prediction problem in all 6 synthetic cases. That result does not make MCC mandatory, but it shows why F1 should be reported with the full confusion matrix rather than treated as a complete evaluation.
Read about machine learning frameworks to understand where evaluation metrics sit in a production workflow. The objective function guide explains how training goals differ from the metrics used to judge a finished model.
The Bayesian machine learning guide provides additional context for reasoning about prediction uncertainty.
Accuracy is the share of all predictions that are correct. F1 combines precision and recall for a chosen positive class. Use F1 when false positives and false negatives both matter, especially when a high accuracy score could come from correctly predicting a large majority class.
No. With standard precision and recall definitions, F1 ranges from 0 to 1. A score of 0 means precision or recall is zero. A score of 1 means every predicted positive is correct and every actual positive is found.
Only if F1 reflects the real decision. Tune the classification threshold on validation data, then assess the resulting false positives and false negatives against operational cost. A higher F1 score can still be the wrong outcome when one error type is much more expensive.
This content was generated with the assistance of AI. Our AI prompt chain workflow is carefully grounded and preferences .gov and .edu citations when available. All content is reviewed by a Telnyx employee to ensure accuracy, relevance, and a high standard of quality.