F1 score is an evaluation metric used in classification. It combines precision and recall into one score.
A high F1 score means the model has both strong precision and strong recall.
F1 score matters because accuracy alone can be misleading, especially when one class is much more common than another.
High accuracy hides poor fraud detection.
Precision measures how many predicted positives were actually positive. It is important when false positives are costly.
Precision = True Positives / (True Positives + False Positives)
In spam detection, if an email is predicted as spam, precision tells us how likely it is to actually be spam. High precision means fewer normal emails are marked as spam.
Recall measures how many actual positives were found. It is important when false negatives are costly.
Recall = True Positives / (True Positives + False Negatives)
In disease detection, if a patient truly has a disease, recall tells us how likely the model is to catch that case. High recall means fewer actual disease cases are missed.
The F1 score is the harmonic mean of precision and recall.
F1 Score = 2 × (Precision × Recall) / (Precision + Recall)
F1 score uses the harmonic mean instead of a simple average because the harmonic mean punishes uneven scores.
A model should not get a strong F1 score if either precision or recall is very weak.
Suppose a model has 80% precision and 60% recall.
This score reflects the balance between precision and recall.
A high F1 score means both precision and recall are strong.
The model makes trustworthy positive predictions and finds most actual positives. A high F1 score is useful when both false positives and false negatives matter.
A low F1 score means precision, recall, or both are weak.
Accuracy measures overall correctness. F1 score focuses on the balance between precision and recall.
Out of all predictions, how many were correct?
How well does the model balance finding positives and making correct positive predictions?
F1 score is often better than accuracy when classes are imbalanced.
Precision focuses only on the quality of positive predictions. F1 score includes precision but also considers recall.
A model with high precision but low recall makes trustworthy positive predictions, but misses many actual positives.
F1 score will show that the model still has a weakness.
Recall focuses only on finding actual positives. F1 score includes recall but also considers precision.
A model with high recall but low precision finds many actual positives, but also creates many false positives.
F1 score will show that the model still has a weakness.
F1 score is useful when both false positives and false negatives matter.
F1 score is useful, but it does not show every detail of model performance.
If false positives and false negatives have very different costs, precision and recall should also be reviewed separately.
F1 score is especially useful for imbalanced datasets because it focuses on positive-class performance.
Fraud cases are rare. Most transactions are normal, so accuracy can look high without catching any fraud.
F1 score focuses on whether the model correctly finds the fraud class — making it more informative than accuracy for rare but important positives.
In spam detection, both false positives and false negatives matter.
In medical diagnosis, recall is often very important, but precision also matters because false alarms can create stress or unnecessary follow-up.
F1 score shows how balanced the model is overall. For high-risk healthcare tasks, precision and recall should still be reviewed separately.
In fraud detection, recall helps catch fraud, while precision helps avoid blocking normal transactions.
Many fraud cases are caught, but many normal transactions are flagged.
Fraud alerts are trustworthy, but too much fraud is missed.
F1 score helps evaluate the balance.
F1 score is based on values from the confusion matrix. It uses true positives, false positives, and false negatives.
F1 does not directly use True Negatives. When true negatives dominate the dataset, accuracy may look high, but F1 score focuses on positive-class performance.
This example shows how precision, recall, and F1 score can be calculated from confusion matrix values.
A perfect F1 score means both precision and recall are perfect.
Perfect F1 scores are rare in real-world problems.
An F1 score can be 0 when the model fails to correctly identify positive examples.
A fraud model predicts every transaction as normal.
Macro F1 calculates the F1 score for each class separately and then averages them. Each class is treated equally.
Macro F1 is useful when you care about performance across all classes, including smaller classes.
Micro F1 combines all true positives, false positives, and false negatives across classes before calculating F1.
Combines results across all classes first and gives more weight to larger classes.
Micro F1 is useful when overall performance across all examples matters. In some cases, micro F1 can behave similarly to accuracy.
Weighted F1 calculates the F1 score for each class and averages them based on how many examples each class has.
Larger classes have more influence. If Class A has many examples and Class B has few, Class A affects weighted F1 more.
Weighted F1 is useful when classes are imbalanced but you still want a score that reflects class size.
| F1 Type | Best Used When |
|---|---|
| Macro F1 | Every class should matter equally |
| Micro F1 | Overall example-level performance matters |
| Weighted F1 | Classes are imbalanced and class size matters |
Many classification models output probabilities. A threshold decides when the model predicts positive.
Changing the threshold can affect precision, recall, and F1 score. A threshold that maximizes F1 may not be the same as the one that maximizes accuracy.
Lowering or raising the threshold changes the balance between precision and recall.
F1 score helps find a balance. The best threshold should match the real-world cost of mistakes.
A model has a precision of 0.75 and a recall of 0.60.
Calculate the F1 score. Then explain what the score means and why it is useful to look at F1 score instead of accuracy alone.
Ask the AI if you need help understanding F1 score, precision, recall, harmonic mean, confusion matrices, thresholds, macro F1, micro F1, or weighted F1.