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)

F1=2PrecisionRecallPrecision+RecallF1 = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}}


๐Ÿ” 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    RecallF1 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

Fฮฒ=(1+ฮฒ2)PrecisionRecallฮฒ2Precision+RecallF_\beta = (1 + \beta^2) \cdot \frac{\text{Precision} \cdot \text{Recall}}{\beta^2 \cdot \text{Precision} + \text{Recall}}

๐Ÿ” Role of ฮฒ (Beta)

  • Controls importance of recall vs precision

๐Ÿ“Š Interpretation

ฮฒ ValueEmphasis
ฮฒ = 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

MethodFocus
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

Precision=TPTP+FP=4040+20=4060=0.67\text{Precision} = \frac{TP}{TP + FP} = \frac{40}{40 + 20} = \frac{40}{60} = 0.67

๐Ÿ”น Step 2: Compute Recall

Recall=TPTP+FN=4040+10=4050=0.80\text{Recall} = \frac{TP}{TP + FN} = \frac{40}{40 + 10} = \frac{40}{50} = 0.80

๐Ÿ”น Step 3: Compute F1 Score

F1=20.670.800.67+0.80F1 = 2 \cdot \frac{0.67 \cdot 0.80}{0.67 + 0.80}

F1=20.5361.470.73F1 = 2 \cdot \frac{0.536}{1.47} \approx 0.73

✅ 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

1010+5=1015=0.67\frac{10}{10 + 5} = \frac{10}{15} = 0.67

๐Ÿ”น Step 2: Recall

1010+40=1050=0.20\frac{10}{10 + 40} = \frac{10}{50} = 0.20

๐Ÿ”น Step 3: F1 Score

F1=20.670.200.67+0.20F1 = 2 \cdot \frac{0.67 \cdot 0.20}{0.67 + 0.20} =20.1340.870.31= 2 \cdot \frac{0.134}{0.87} \approx 0.31

✅ 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

F2=(1+22)0.60.9220.6+0.9​


๐Ÿ”น Step 2: Solve

F2=50.542.4+0.9=50.543.3=50.164=0.82F_2 = 5 \cdot \frac{0.54}{2.4 + 0.9} = 5 \cdot \frac{0.54}{3.3} = 5 \cdot 0.164 = 0.82

✅ 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

F0.5=(1+0.52)0.90.50.520.9+0.5F_{0.5} = (1 + 0.5^2) \cdot \frac{0.9 \cdot 0.5}{0.5^2 \cdot 0.9 + 0.5}

๐Ÿ”น Step 2: Solve

=1.250.450.225+0.5=1.250.450.7251.250.62=0.78= 1.25 \cdot \frac{0.45}{0.225 + 0.5} = 1.25 \cdot \frac{0.45}{0.725} \approx 1.25 \cdot 0.62 = 0.78

✅ 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:

F1=20.80.60.8+0.6=20.481.4=0.69F1 = 2 \cdot \frac{0.8 \cdot 0.6}{0.8 + 0.6} = 2 \cdot \frac{0.48}{1.4} = 0.69

Model B:

F1=20.60.90.6+0.9=20.541.5=0.72F1 = 2 \cdot \frac{0.6 \cdot 0.9}{0.6 + 0.9} = 2 \cdot \frac{0.54}{1.5} = 0.72

✅ 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

Popular posts from this blog

Machine Learning PCCST503 Semester5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Machine Learning (ML)

Distinguishing Machine Learning from Traditional Programming