The F1 score is a statistical measure of a test's accuracy that combines precision (the fraction of retrieved entities that are relevant) and recall (the fraction of relevant entities that are retrieved). It is calculated as 2 * (Precision * Recall) / (Precision + Recall), yielding a value between 0 and 1. Unlike simple accuracy, the F1 score does not inflate performance on datasets where negative cases vastly outnumber positive ones, making it the standard metric for medical named entity recognition tasks where clinical concepts like adverse drug events are sparse.
Glossary
F1 Score

What is F1 Score?
The F1 score is the harmonic mean of precision and recall, providing a single balanced metric for evaluating clinical entity recognition systems, especially on imbalanced datasets where one class is rare.
In clinical NLP pipelines, the F1 score is computed at both the token level and the span level to evaluate exact boundary matching of entities like medications or diseases. A high F1 score indicates the model effectively balances finding all true clinical mentions without overwhelming clinicians with false positives. It is the primary metric reported in benchmarks using datasets like i2b2 and is central to cross-validation and inter-annotator agreement studies that validate gold-standard corpora.
Key Characteristics of the F1 Score
The F1 Score is the harmonic mean of precision and recall, providing a single, balanced metric that is essential for evaluating models on datasets with significant class imbalance, such as clinical entity recognition.
The Harmonic Mean Formula
The F1 Score is calculated as 2 * (Precision * Recall) / (Precision + Recall) . Unlike a simple arithmetic mean, the harmonic mean severely penalizes extreme disparities between precision and recall. A model that achieves high precision by finding only one easy entity will have a very low F1 Score, forcing a balanced optimization.
Handling Class Imbalance
Accuracy is a misleading metric for clinical NER because the vast majority of tokens in a medical record are 'O' (Outside any entity). A model that predicts 'O' for every token would have high accuracy but an F1 Score of zero. The F1 Score ignores true negatives, focusing exclusively on the model's ability to correctly identify the rare, critical clinical entities like diseases, medications, and procedures.
Precision vs. Recall Trade-off
The F1 Score quantifies the trade-off between two competing errors:
- Precision: Of all the entities the model predicted, how many were correct? High precision means fewer false alarms.
- Recall: Of all the actual entities in the text, how many did the model find? High recall means fewer missed diagnoses. A high F1 Score confirms the model is both accurate in its predictions and thorough in its detection.
Micro, Macro, and Weighted Averaging
For multi-class NER problems, F1 must be aggregated across all entity types:
- Micro-F1: Calculates metrics globally by counting total true positives, false negatives, and false positives. It favors performance on frequent entities.
- Macro-F1: Calculates the F1 for each entity type independently and takes the unweighted mean. It treats rare entities like 'Adverse Event' as equally important as common ones like 'Drug'.
- Weighted-F1: A mean weighted by each class's support (number of true instances), balancing the two approaches.
Strict vs. Lenient Matching
The F1 Score's value depends heavily on the evaluation script's boundary matching rules:
- Strict/Exact Match: The predicted entity span must perfectly align with the gold-standard annotation. A single token offset counts as a false positive and a false negative.
- Lenient/Overlap Match: Any overlap between the predicted and true span is considered a true positive. This is often used in medication extraction where capturing the core drug name is more critical than exact dosage boundaries.
Limitations as a Single Metric
While powerful, the F1 Score is not a complete picture of model performance. It treats precision and recall as equally important, which may not be true for all clinical use cases. A screening application might prioritize recall (finding every possible case) over precision, while an automated billing system might demand extremely high precision to avoid claim denials. Always evaluate F1 alongside raw precision and recall values.
Frequently Asked Questions
Clear answers to the most common questions about using the F1 score to evaluate clinical named entity recognition systems on imbalanced medical datasets.
The F1 score is the harmonic mean of precision and recall, providing a single balanced metric that penalizes extreme trade-offs between the two. It is calculated as 2 * (Precision * Recall) / (Precision + Recall). Unlike arithmetic averaging, the harmonic mean ensures the F1 score is low if either precision or recall is poor. For example, if a clinical NER model achieves 95% precision but only 50% recall, the F1 score is approximately 65.5%, accurately reflecting the model's failure to find half the entities. The score ranges from 0.0 to 1.0, with 1.0 representing perfect precision and recall. In medical entity extraction, this metric is preferred over accuracy because it is robust to the severe class imbalance inherent in clinical text, where 'O' (Outside) tags vastly outnumber entity tags like B-Drug or I-Disease.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The F1 score does not exist in isolation. It is the harmonic mean of two fundamental metrics and is deeply connected to the evaluation strategies used for imbalanced clinical datasets.
Precision
Measures the exactness of a model. It answers: Of all the entities the model predicted as 'Medication', how many were actually correct? High precision is critical in clinical workflows to prevent alert fatigue caused by false positives.
- Formula: True Positives / (True Positives + False Positives)
- Clinical Context: A low precision in medication extraction means the system is flagging too many non-drug terms, wasting pharmacist review time.
Recall
Measures the completeness of a model. It answers: Of all the actual 'Disease' entities in the text, how many did the model successfully find? High recall is vital for safety to ensure no critical finding is missed.
- Formula: True Positives / (True Positives + False Negatives)
- Clinical Context: A low recall in pathology report extraction might miss a malignant diagnosis, posing a direct risk to patient safety.
Imbalanced Dataset Evaluation
In clinical Named Entity Recognition, 'O' (Outside) tags vastly outnumber entity tags like 'B-Drug'. Accuracy is a misleading metric here because a model that predicts 'O' for everything scores highly but is clinically useless. The F1 score is the standard metric because it ignores true negatives and focuses solely on the model's ability to correctly identify the rare positive entity classes.
Micro vs. Macro Averaging
When evaluating multi-class NER (e.g., drugs, diseases, procedures), the aggregation method matters.
- Micro-F1: Aggregates contributions of all classes globally. It is heavily influenced by the performance on frequent classes.
- Macro-F1: Calculates the F1 for each class independently and takes the unweighted mean. This penalizes the model more severely for poor performance on rare entities like 'Lab Value'.
Confusion Matrix
The raw data structure from which the F1 score is derived. For sequence labeling, it visualizes the True Positives, False Positives, True Negatives, and False Negatives for each entity type. Analyzing the confusion matrix reveals specific systematic errors, such as the model frequently confusing 'Procedure' with 'Lab Test'.
Exact Match vs. Relaxed Match
The strictness of evaluation drastically changes the F1 score.
- Exact Match: Requires the predicted span boundaries to perfectly align with the gold standard annotation.
- Relaxed Match: Often allows partial overlap. A prediction of 'severe chest pain' for a gold label of 'chest pain' would be a false positive in exact match but a true positive in relaxed match. Clinical NLP typically reports strict F1 to ensure boundary integrity.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us