F1 Score
When you build a classifier, you usually care about two different kinds of mistakes: flagging a normal thing as positive, and missing a truly positive thing. The F1 score is a single number that balances those two concerns, which is why it shows up so often in real classification work.
What it measures
The F1 score is the harmonic mean of precision and recall. Precision answers: “Of the items I predicted as positive, how many were truly positive?” Recall answers: “Of all truly positive items, how many did I catch?” F1 combines them as:
F1 = 2 * (precision * recall) / (precision + recall)
The harmonic mean is intentionally strict: if either precision or recall is low, the F1 score drops sharply. That makes F1 a good “both must be decent” metric.
Why it matters in practice
Accuracy can look great when classes are imbalanced (for example, fraud is rare). F1 focuses on performance for the positive class, using the confusion matrix counts (TP, FP, FN) and ignoring TN. Typical uses:
- Spam detection: avoid marking legitimate email as spam (precision) while still catching spam (recall).
- Disease screening: missing cases is costly (recall), but too many false alarms overload clinics (precision).
- Fraud detection: you want flagged transactions to be truly suspicious, without letting fraud slip through.
How you’ll see it in tools
In scikit-learn, you’ll encounter it as sklearn.metrics.f1_score(y_true, y_pred). For multi-class problems, variants like macro F1 (treat classes equally) and weighted F1 (weight by class frequency) change what “balanced” means.
The F1 Score is a classification metric defined as the harmonic mean of precision and recall: F1 = 2·(precision·recall)/(precision+recall). It ranges from 0 to 1 and is high only when both false positives and false negatives are low. It matters because it summarizes the precision–recall tradeoff in a single number, making it a standard choice for evaluating models on imbalanced classes.
Think of a smoke alarm: you want it to ring when there’s a real fire, but not go off every time you burn toast. The F1 Score is a single number that captures that balance for an AI that makes yes/no decisions (like “spam” vs “not spam,” or “fraud” vs “not fraud”).
It combines two ideas: precision (when the model says “yes,” how often it’s right) and recall (how many of the real “yes” cases it actually catches). The F1 Score is especially useful when “yes” cases are rare, so plain accuracy can look misleading.