F-Measure
๐ง What is the F-Measure?
๐น Definition
The F-measure (F-score) is a metric that combines:
- Precision
- Recall
into a single value.
It is especially useful when there is a tradeoff between precision and recall.
๐ Why Do We Need F-Measure?
Accuracy can be misleading in many cases (e.g., imbalanced data).
Instead, we care about:
- How many predicted positives are correct → Precision
- How many actual positives are detected → Recall
๐ F-measure balances both.
๐ F1 Score (Most Common Form)
๐ Interpretation
- Harmonic mean of precision and recall
- Gives equal importance to both
๐ฏ Key Property
- High only when both precision and recall are high
- Penalizes extreme imbalance between them
⚖️Why Harmonic Mean?
Instead of arithmetic mean:
- Arithmetic mean ignores imbalance
- Harmonic mean is sensitive to low values
๐ If either precision or recall is low → F1 drops significantly
๐ Example
| Precision | Recall | F1 Score |
|---|---|---|
| 1.0 | 0.0 | 0 |
| 0.9 | 0.9 | 0.9 |
| 0.9 | 0.1 | Low (~0.18) |
๐ Shows balance requirement
๐ General Form: Fฮฒ Score
๐ Formula
๐ Role of ฮฒ (Beta)
- Controls importance of recall vs precision
๐ Interpretation
| ฮฒ Value | Emphasis |
|---|---|
| ฮฒ = 1 | Equal (F1) |
| ฮฒ > 1 | Recall more important |
| ฮฒ < 1 | Precision more important |
๐ฏ Common Variants
๐น F1 Score (ฮฒ = 1)
- Equal weight to precision and recall
๐น F2 Score (ฮฒ = 2)
- Recall emphasized
- Used when missing positives is costly
๐น F0.5 Score (ฮฒ = 0.5)
- Precision emphasized
- Used when false positives are costly
๐ง Intuitive Understanding
Precision Focus:
“When I predict positive, I want to be correct”
Recall Focus:
“I want to find all positives”
F-Measure:
“Balance both objectives”
๐When to Use F-Measure
✅ Suitable When:
- Class imbalance exists
- Both FP and FN matter
- Need a single metric
❌ Not Ideal When:
- True negatives are important
- Probabilities are required
๐ Multi-Class F-Measures
๐น Macro F1
- Compute F1 per class
- Average equally
๐ Treats all classes equally
๐น Micro F1
- Aggregate TP, FP, FN globally
- Then compute F1
๐ Dominated by majority class
๐น Weighted F1
- Weighted by class frequency
๐ Balances class importance
๐ Comparison of Averaging
| Method | Focus |
|---|---|
| Macro | Minority classes |
| Micro | Overall performance |
| Weighted | Balanced |
๐งช Practical Example
Suppose:
- High precision, low recall → model misses many positives
- High recall, low precision → many false alarms
๐ F1 gives a balanced score
⚠️ Limitations of F-Measure
๐น Ignores True Negatives
- Does not consider TN
- Not suitable for some applications
๐น Equal Weight Assumption (F1)
- May not match real-world costs
๐น Threshold Dependent
- Depends on classification threshold
๐ Significance in Machine Learning
F-measure is widely used in:
- Information retrieval
- NLP tasks (e.g., named entity recognition)
- Medical diagnosis
- Imbalanced classification
๐ฏKey Takeaways
- F-measure combines precision and recall
- F1 is most commonly used
- Fฮฒ allows flexible weighting
- Essential for imbalanced datasets
- Must be chosen based on application needs
๐งฎ Example 1: Basic F1 Score Calculation
๐ Given Confusion Matrix
| Predicted + | Predicted - | |
|---|---|---|
| Actual + | TP = 40 | FN = 10 |
| Actual - | FP = 20 | TN = 30 |
๐น Step 1: Compute Precision
๐น Step 2: Compute Recall
๐น Step 3: Compute F1 Score
✅ Final Answer:
- Precision = 0.67
- Recall = 0.80
- F1 Score ≈ 0.73
๐งฎ Example 2: Imbalanced Scenario
๐ Given
| Predicted + | Predicted - | |
|---|---|---|
| Actual + | TP = 10 | FN = 40 |
| Actual - | FP = 5 | TN = 945 |
๐น Step 1: Precision
๐น Step 2: Recall
๐น Step 3: F1 Score
✅ Insight
- Precision looks good (0.67)
-
But recall is poor (0.20)
๐ F1 drops to 0.31, revealing poor performance
๐งฎ Example 3: Fฮฒ Score (Recall Emphasis)
๐ Given:
- Precision = 0.6
- Recall = 0.9
- ฮฒ = 2 (Recall more important)
๐น Step 1: Apply Formula
๐น Step 2: Solve
✅ Interpretation
- High recall → boosted score
- F2 = 0.82 (higher than F1 would be)
๐งฎ Example 4: F0.5 Score (Precision Emphasis)
๐ Given:
- Precision = 0.9
- Recall = 0.5
- ฮฒ = 0.5 (Precision more important)
๐น Step 1: Formula
๐น Step 2: Solve
✅ Interpretation
- Precision is high → score is boosted
- F0.5 = 0.78
๐งฎ Example 5: Comparing Two Models
๐ Model A:
- Precision = 0.8
- Recall = 0.6
๐ Model B:
- Precision = 0.6
- Recall = 0.9
๐น Compute F1
Model A:
Model B:
✅ Conclusion
- Model B has higher F1
- Better balance between precision and recall
๐ฏ Key Teaching Insights
- F1 penalizes imbalance between precision and recall
- Fฮฒ allows task-specific weighting
- Useful in imbalanced datasets
- Always interpret alongside precision & recall
Comments
Post a Comment