Evaluating Text Classification Systems
Machine LearningModel answerLast updated
Walk through how you evaluate NLP classification models, covering core metrics, business tradeoffs, class imbalance, and connecting evaluation choices to real decisions.
You're working on a text classification system—perhaps categorizing support tickets, flagging policy violations in user content, or routing customer messages. Your task is to demonstrate how you think about evaluating such a model, from explaining fundamentals to connecting metric choices with product impact.
Work through the following parts. Show that you can define metrics precisely, reason about tradeoffs in terms of real costs, and tie evaluation decisions to business outcomes.
Setting
- You're evaluating a classification model (binary or multi-class) in a production context, not an academic benchmark
- Class distributions may be heavily skewed—the category you care about most (fraud, urgent escalations, violations) is often rare
- The model produces probabilities or scores; you choose a threshold to convert them into actions
- Predictions may trigger automated responses (blocking, routing) or feed a human review queue
- Business costs of false positives and false negatives are rarely equal
Clarifying Questions You Should Ask
- Binary or multi-class? How many categories?
- What's the class distribution, and which class is most critical?
- What happens after prediction—automated action or human review?
- What are the relative costs of mistakenly flagging something vs. missing it?
- Are there latency or computational constraints?
Part 1: Explain a confusion matrix to high school students
Describe what a confusion matrix is using plain language and a concrete example. No jargon, no formulas.
What to cover: An accessible explanation with a real-world example, the four outcomes, and why distinguishing types of mistakes matters more than just counting errors.
Part 2: Define precision, recall, F1, and AUC
Give precise definitions of precision, recall, F1 score, and AUC, including formulas. State in one sentence what each metric tells you.
What to cover: Correct formulas using TP/FP/FN/TN, intuition for each metric, and awareness that PR AUC (precision-recall) is better than ROC AUC under heavy imbalance.
Part 3: When to prioritize precision vs. recall
Explain when you'd prioritize precision over recall and vice versa. Root your reasoning in a decision principle, not just examples.
What to cover: The cost-based criterion (relative severity of false positives vs. false negatives), how threshold tuning trades one for the other, and that F_β encodes asymmetric priorities.
Part 4: Evaluating multi-class models
How do you evaluate a model that predicts one of K categories? Go beyond overall accuracy.
What to cover: The K×K confusion matrix, per-class metrics, choosing among micro/macro/weighted averaging based on whether rare classes matter, and additional concerns like calibration and slice-level performance.
Part 5: Cross-entropy loss
What is cross-entropy loss and why is it the default for classification? Provide both binary and multi-class formulations.
What to cover: Correct formulas, the probabilistic interpretation (log-likelihood), and why it's preferred—sharp penalties for confident mistakes and clean gradients.
Part 6: When human evaluation is necessary
In what situations does human evaluation beat automatic metrics? What are the costs and pitfalls?
What to cover: Tasks where automatic metrics proxy poorly for real quality, failure modes (gaming metrics, surface-level similarity), and the rigor needed for credible human studies (rubrics, blind rating, inter-annotator agreement).
Part 7: Describing a past NLP project
What structure and technical details should you include when describing an NLP project you've worked on?
What to cover: A lifecycle view—problem framing, data and labels, baseline vs. complex models, metric justification, error analysis, deployment impact—with honest tradeoffs and lessons learned.
Hints
Hint 1
Start Part 1 with a relatable scenario like spam detection or medical test results
Hint 2
For Part 3, think about the *cost* of each mistake type rather than listing use cases
Hint 3
In Part 4, remember that macro-averaging treats all classes equally while micro-averaging weights by frequency
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Part 1: Confusion Matrix for High School Students
Imagine you built an app that scans photos and tells you whether there's a dog in the picture. You test it on 100 photos: 60 actually have dogs, 40 don't.
A confusion matrix is a simple table showing four outcomes:
- Correct dog detection: The app says "dog" and there really is one (say, 50 photos)
- Missed dogs: The app says "no dog" but there actually is one (10 photos)
- False alarms: The app says "dog" but the photo is just a cat or a couch (5 photos)
- Correct rejection: The app says "no dog" and it's correct (35 photos)
Why does this matter? Because not all mistakes are equal. Missing a dog might just mean a missed cute moment. But if this were a medical test detecting disease, missing a case (false negative) could be life-threatening, while a false alarm (false positive) might just mean an extra follow-up test. The confusion matrix lets you see which kind of mistake you're making, so you can decide if your system is good enough for the real world.
Part 2: Precision, Recall, F1, and AUC
Precision = TP / (TP + FP)
How many of the items you flagged as positive are actually positive? High precision means few false alarms.
Recall (Sensitivity) = TP / (TP + FN)
How many of the actual positives did you catch? High recall means you're not missing many.
F1 Score = 2 · (Precision × Recall) / (Precision + Recall)
The harmonic mean of precision and recall; balances both when you care about them equally.
ROC AUC (Area Under the Receiver Operating Characteristic Curve)
The probability that the model ranks a random positive example higher than a random negative example; threshold-independent summary of ranking quality. Ranges from 0 to 1 (0.5 = random).
Important for imbalanced data: Under heavy class imbalance, PR AUC (Precision-Recall AUC) is more informative than ROC AUC, because ROC AUC can look deceptively good when negatives dominate.
Part 3: Precision vs. Recall Tradeoff
Decision principle: Prioritize the metric that reflects the cost of each error type.
-
Prioritize precision when false positives are expensive—blocking legitimate users, wasting investigator time, or damaging trust. Example: flagging content for removal where mistakes upset innocent users.
-
Prioritize recall when false negatives are expensive—missing fraud, failing to catch safety violations, or letting urgent cases slip through. Example: detecting medical emergencies or financial fraud.
The threshold lever: Lowering the decision threshold increases recall (you catch more positives) but decreases precision (more false alarms). Raising it does the opposite.
F_β score generalizes F1: F_2 weights recall twice as much as precision; F_0.5 favors precision. The default threshold of 0.5 is arbitrary—choose it based on the cost ratio, not convention.
Part 4: Multi-Class Evaluation
Beyond accuracy: Overall accuracy hides which classes the model struggles with, especially if some classes are rare.
K×K confusion matrix: Shows true vs. predicted for all K classes; reveals specific confusion pairs (e.g., "urgent" mislabeled as "medium priority").
Per-class metrics: Compute precision, recall, and F1 for each class individually.
Aggregation strategies:
- Macro-average: Treat all classes equally (average per-class metrics). Use when rare classes matter.
- Micro-average: Weight by support (sum TP/FP/FN across classes). Emphasizes frequent classes.
- Weighted average: Weight by class frequency. Balances the two.
Additional considerations:
- Calibration: Are predicted probabilities well-calibrated? Matters if downstream systems use them for ranking or cost-benefit decisions.
- Slice evaluation: Performance on subgroups (language, topic, time period) may vary; aggregate metrics can mask critical failures.
Part 5: Cross-Entropy Loss
Binary cross-entropy:
L = -[y log(p) + (1 - y) log(1 - p)]
where y ∈ {0,1} is the true label and p is the predicted probability.
Multi-class (categorical) cross-entropy:
L = -Σ y_i log(p_i)
where y is a one-hot vector and p is the predicted probability distribution (softmax output).
Interpretation: Cross-entropy measures how well the predicted probability distribution matches the true label distribution. Equivalently, it's the negative log-likelihood of the true label under the model's predictions.
Why it's the default:
- Sharp penalty for confident mistakes: Predicting 0.01 when the truth is 1 incurs much larger loss than predicting 0.4.
- Probabilistic grounding: Directly connected to maximum likelihood estimation.
- Clean gradients: Differentiable everywhere, works well with gradient descent and backpropagation.
Part 6: When Human Evaluation Beats Automatic Metrics
When human eval is necessary:
- Subjective quality dimensions: Fluency, coherence, tone, creativity, helpfulness—hard to capture with BLEU or ROUGE.
- Adversarial gaming: Models optimizing directly for automatic metrics can exploit surface patterns (Goodhart's law).
- Noisy or outdated references: Automatic metrics rely on gold references that may be incomplete, biased, or stale.
- Safety and policy: Detecting subtle harm, bias, or policy violations often requires human judgment.
Costs and pitfalls of human evaluation:
- Expensive and slow: Doesn't scale to rapid iteration.
- Subjective and noisy: Raters disagree; need multiple raters and inter-annotator agreement (Cohen's kappa, Fleiss' kappa).
- Bias and drift: Raters may anchor to early examples, tire over time, or bring their own biases.
- Controls needed: Clear rubrics, blind rating (hide model identity), randomized presentation, and statistical testing for significance.
Hybrid approach: Use automatic metrics for fast iteration and human eval for final validation or to audit metric-model alignment.
Part 7: Describing an NLP Project
Structure of a strong answer:
-
Problem framing: What business problem were you solving? What was the input, output, and success criterion?
-
Data and labeling: How much data? How did you acquire and label it? What was the quality and any noise or bias?
-
Baseline vs. complex models: Start with simple baselines (rules, keyword matching, logistic regression). Justify if and when you moved to neural models—what did complexity buy you?
-
Metric choice: Which metrics mattered and why? How did class imbalance or downstream costs inform your choice?
-
Error analysis: What did the model get wrong? What patterns emerged? Did you address them (more data, feature engineering, rebalancing)?
-
Deployment and impact: How did the model perform in production? What was the business impact (time saved, accuracy gain, cost reduction)? What tradeoffs did you make (latency, interpretability)?
-
Lessons learned: What would you do differently? When did a simpler approach win? Be honest about mistakes and iterations.
Red flags to avoid:
- Jumping straight to the fanciest model without justification.
- Claiming perfect results with no error analysis.
- Ignoring deployment constraints (latency, cost, interpretability).
- Using accuracy as the sole metric on imbalanced data.
Maturity signals:
- Defending a simpler model when it met requirements.
- Showing awareness of labeling quality and annotator agreement.
- Discussing the feedback loop between model errors and data collection.
- Acknowledging what you learned from failure modes.