Course contentsShow
← Machine Learning and Deep Learning
Lesson 1285 of 3,53829. Core NLP TasksFree lesson

Evaluation Metrics for Text Classification

Choosing appropriate metrics: accuracy, F1, precision-recall for imbalanced classes, and macro vs micro averaging.

Evaluation Metrics for Text Classification

What you'll learn: How to choose the right metrics to measure your text classifier's performance, especially when dealing with imbalanced classes.

Why Metrics Matter

After training a text classifier, you need to measure how well it works. But not all metrics tell the full story. Choosing the wrong metric can make a terrible model look great—or hide what it's actually good at.

Core Metrics Explained

Accuracy

The percentage of predictions that are correct. Simple, but misleading with imbalanced data. If 95% of emails are "not spam," a lazy model that always predicts "not spam" gets 95% accuracy while catching zero spam!

Precision and Recall

  • Precision: Of all items predicted as positive, how many truly are? (Quality of positive predictions)
  • Recall: Of all actual positives, how many did we catch? (Coverage of positives)

Think of a spam filter: High precision means few false alarms (good emails marked spam). High recall means catching most actual spam.

F1 Score

The harmonic mean of precision and recall—a single number balancing both. Use this when you care equally about false positives and false negatives.

Handling Multiple Classes

Macro Averaging

Calculate metrics for each class separately, then average them. Treats all classes equally—good for imbalanced datasets where you care about minority classes.

Micro Averaging

Pool all predictions together, then calculate metrics globally. Dominated by frequent classes—use when larger classes matter more.

Key Takeaway: For imbalanced text classification, avoid relying solely on accuracy. Use F1 score (especially macro-averaged) and examine precision-recall trade-offs to understand your model's true performance across all classes.