Beginner level · Module 5: Introduction to Text Classification · Lesson 3 of 3
Evaluating a Classifier and Analysing Errors
Learners measure accuracy, read a confusion matrix, compute precision and recall for one category and study the misclassified messages to decide what to improve.
In this lesson you will
- Evaluate a classifier with a confusion matrix
- Analyse errors and propose improvements
Key concepts
accuracyconfusion matrixprecisionrecallerror analysis
The lesson
Accuracy is the share of correct predictions, but it hides which categories fail. A confusion matrix shows, for each true category, how messages were predicted. The diagonal is correct; everything else is an error.
Precision for 'complaint' asks: of the messages predicted as complaints, how many really were? Recall asks: of the real complaints, how many were found? Missing complaints (low recall) is usually worse than an extra message in the complaints queue.
Error analysis means reading the wrong predictions and grouping them by cause: unusual spelling, mixed languages, very short messages or wrong labels. Each group suggests a fix such as a normalisation rule, more examples or a relabelled message.
Step by step
- Compute accuracy_score and confusion_matrix on the test set.
- Compute precision and recall for each category with classification_report.
- Read every misclassified complaint and group the causes.
- Propose and test one improvement.
Evaluating an enquiry router on 200 test messages
Per-category precision, recall and F1 from one confusion matrix show where the router fails, which overall accuracy hides.
Accuracy
86.5%
173 of 200 messages
Synthetic test set
Macro F1
86.9%
Each category weighted equally
Complaint recall
84.0%
8 of 50 complaints misrouted
Spam precision
93.2%
3 genuine messages flagged as spam
Show the data behind the chart
| Category | Messages | Precision (%) | Recall (%) | F1 (%) |
|---|---|---|---|---|
| Complaint | 50 | 85.7 | 84 | 84.8 |
| Enquiry | 60 | 81.3 | 86.7 | 83.9 |
| Service request | 48 | 88.4 | 79.2 | 83.5 |
| Spam | 42 | 93.2 | 97.6 | 95.3 |
Interpretation
Overall accuracy is 86.5%, but 8 of the 50 complaints were routed elsewhere (5 to enquiries, 2 to service requests and 1 to spam), so they would wait in the wrong queue.
Service requests have the lowest recall (79.2%): 6 were mistaken for enquiries, probably because both often start with a question.
Spam is handled best (F1 95.3%), but 3 genuine messages (1 complaint, 1 enquiry, 1 service request) were flagged as spam, which means they might never be read.
Recommendations
- Never delete messages flagged as spam automatically; review the spam queue daily.
- Lower the decision threshold for complaints or send every low-confidence message to a person, then re-measure complaint recall.
- Add more labelled service requests phrased as questions, and re-test on a fresh set.
Practice activity
Write an evaluation note for the project classifier with a confusion matrix, per-category recall and grouped errors.
Expected result: A correct evaluation and an improvement tested against the original result.
Check your understanding
-
What does recall for complaints measure?
Show answer
The share of real complaints that the system correctly identified.
-
Why read misclassified messages?
Show answer
To find the causes of errors and decide what to fix.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.