Telnyx - Global Communications Platform ProviderHome
Voice AI AgentsText-to-SpeechSpeech-to-TextEmbeddingsSearch APIBrowser APIMeetingBotVoice DesignInference APIAgentSDKFunctionsStateful ActorsKVSQLDBStorageGlobal NumbersVoice APISIP TrunkingSMS APIEmail APIRCSWhatsAppWebRTCVerify APINumber ReputationNumber LookupDeepfake DetectionBranded CallingIoT SIMeSIMMobile VoicePrivate Wireless GatewaysVirtual Cross ConnectsCloud VPNGlobal IP200+ open-source buildsagent-signup.mdx402View all primitivesHealthcareFinanceTravel and HospitalityLogistics and TransportationContact CenterInsuranceRetail and E-CommerceSales and MarketingServices and DiningView all solutionsVoice AIVoice APIInferenceMobile VoiceSpeech-to-TextText-to-SpeechSIP TrunkingSMS APIWhatsApp Business APIGlobal NumbersIoT SIM CardView all pricingOur NetworkGlobal communicationsEdge ComputeAgents PlatformPartnersCareersCustomer storiesResource centerMission Control PortalEventsSupport centerSETIDev DocsIntegrations
Contact usLog in
Contact usLog inSign up

Social

Company

  • Our Network
  • Global Coverage
  • Release Notes
  • Careers
  • Voice AI
  • AI Glossary
  • Shop

Legal

  • Data and Privacy
  • Report Abuse
  • Privacy Policy
  • Cookie Policy
  • Law Enforcement
  • Acceptable Use
  • Trust Center
  • Country Specific Requirements
  • Website Terms and Conditions
  • Terms and Conditions of Service

Compare

  • ElevenLabs
  • Vapi
  • Baseten
  • Together.ai
  • Twilio
  • Bandwidth
  • Vonage
  • Amazon Connect
  • Cloudflare
© Telnyx LLC 2026
ISO • PCI • HIPAA • GDPR • SOC2 Type II

Ask AI

  • GPT
  • Claude
  • Perplexity
  • Gemini
  • Grok
Back to Glossary

F1 Score Formula: How to Calculate and Interpret It

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.

Maeve Sentner
Editor: Maeve Sentner

Updated August 2026

What is the F1 score?

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.

What is the F1 score formula?

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)

How do you calculate an F1 score?

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.

F1 score example

MeasureFormulaExample result
PrecisionTP / (TP + FP)0.80
RecallTP / (TP + FN)0.80
F1 score2PR / (P + R)0.80

Confusion matrix for a fraud model with 80 true positives, 20 false positives, 20 false negatives, and an F1 score of 0.80.

Is a good F1 score always close to 1?

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.

When is F1 more useful than accuracy?

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.

How do macro, micro, and weighted F1 differ?

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.

Real-world examples of F1 score

F1 is useful when a classifier must balance two costly mistakes. The right balance depends on the decision the model supports.

Use casePositive classError tradeoff
Fraud detectionFraudulent transactionMissing fraud can create direct loss, while excessive false alerts send legitimate customers into review.
Medical screeningPatient likely to have the conditionHigh recall can be important because a missed case may delay care. Precision still matters because false positives can trigger unnecessary follow-up.
Spam filteringSpam messageLow precision can hide legitimate messages. Teams may accept lower recall to avoid putting important email in a spam folder.
Content moderationPolicy-violating contentMissed 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.

How should you use F1 during model evaluation?

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.

How do you choose a classification threshold for F1?

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.

What mistakes make an F1 score misleading?

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.

Related concepts

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.

Frequently asked questions

What is the difference between F1 score and accuracy?

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.

Can the F1 score be negative?

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.

Should I tune a model for the highest F1 score?

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.

Sources

  1. scikit-learn F1 documentation
  2. Google classification guide
  3. Peer-reviewed comparison of MCC, F1, and accuracy
Share on Social

Jump to:

What is the F1 score?What is the F1 score formula?How do you calculate an F1 score?Is a good F1 score always close to 1?When is F1 more useful than accuracy?How do macro, micro, and weighted F1 differ?Real-world examples of F1 scoreHow should you use F1 during model evaluation?How do you choose a classification threshold for F1?What mistakes make an F1 score misleading?Related conceptsFrequently asked questionsSources

Sign up for emails of our latest articles and news

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.

Sign up and start building.

Sign UpContact Us