Natural Language Processing · Beginner level

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

  1. Compute accuracy_score and confusion_matrix on the test set.
  2. Compute precision and recall for each category with classification_report.
  3. Read every misclassified complaint and group the causes.
  4. Propose and test one improvement.
Dashboard

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

Precision and recall by category (%) Precision (%): Complaint 85.7, Enquiry 81.3, Service request 88.4, Spam 93.2. Recall (%): Complaint 84, Enquiry 86.7, Service request 79.2, Spam 97.6 0255075100ComplaintEnquiryService req…SpamPrecision (%)Recall (%)
Show the data behind the chart
CategoryMessagesPrecision (%)Recall (%)F1 (%)
Complaint5085.78484.8
Enquiry6081.386.783.9
Service request4888.479.283.5
Spam4293.297.695.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

  1. What does recall for complaints measure?

    Show answer

    The share of real complaints that the system correctly identified.

  2. 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.