ML Systems Lab Open interactive version →
Intermediate 30 min read error analysisfailure modesslicingdebugging

Error Analysis

Confusion matrix drill-down, error slicing, systematic failures

An NLP intent classifier scores 94% accuracy. The product team is ready to ship. Before you sign off, you pull 200 of its mistakes and actually read them. The breakdown is stark: 67% are short 3-word commands ("turn on light"), 18% are code-switching (Spanish phrases mixed into English), 12% are negations ("don't turn on"), and the remaining 3% is a long tail of one-off causes (typos, out-of-vocabulary slang, garbled audio) too scattered to bucket individually. The model looks great on paper and fails on exactly the inputs your core users send most. That single accuracy number hid all of it.

That is what error analysis is for: turning "the model has 6% error" into "the model fails on 3-word commands, and here is why." The aggregate metric tells you a problem *exists*; error analysis tells you *which* group has it, *what kind* it is, and *what will fix it*.

Before you even sample individual errors, look at the confusion matrix — the table of predicted class vs. actual class counts. It's the fastest way to see *which* classes get confused with which: a spike in the "negation → positive" cell tells you exactly where to start sampling, before you've read a single example.


The five steps

1. Sample the errors — but not uniformly. Sort by confidence and look hardest at the *high-confidence* mistakes (the model said 0.95, the truth was the opposite). Those are not noise; they are the model confidently doubling down on a wrong pattern, and it will keep doing it.

2. Tag each error by cause. A bad training label? Not enough signal for this input type? A rare pattern with too few examples? Or genuine ambiguity that humans disagree on too? Drop every error into a bucket.

3. Count each bucket — both its error rate and how many of the total errors it accounts for.

4. Prioritise by impact × feasibility. A bucket that is 30% of your errors with a known fix beats one that is 5% with a mysterious cause. And weight by *cost*, not just frequency: those 12% negation errors, where the assistant does the exact opposite of what a user asked, may hurt far more than a mangled 3-word command.

5. Trace to root cause. Is it a *data* gap (no examples of this type), a *feature* gap (the model cannot even represent the pattern), or a *distribution* mismatch (production looks different from training)?


Why it pays off

Back to the classifier: two-thirds of the errors are short commands, because the model saw too few of them in training and its vocabulary came from longer queries. The fix is not a bigger model or a new architecture — it is collecting 200 labelled 3-word commands, retraining, and re-measuring that bucket's error rate. One cheap data effort clears the majority of the errors. That is the recurring lesson: systematic errors cluster by group or pattern and have targeted fixes, and collecting data for the worst bucket usually moves the metric more than any architecture change. (Errors that cluster by nothing are just irreducible noise — more data will not help those.)

And never let a high headline number end the conversation. A model that is 96% accurate but fails 100% of the time on one demographic, or a 98% spam filter that misses every email in one language, is not acceptable. Break errors down by subgroup, confidence, input length, and any business-critical slice. The aggregate metric is the *last* thing you report, not the first.

That "one demographic" case is worth naming precisely: error slicing asks *where* the model is wrong, on any slice, so you can fix it. Subgroup fairness analysis is the narrower, harm-focused case of slicing — it asks whether the model is wrong *more often* for a protected group (race, gender, age, disability status, and similar) in a way that causes real-world harm, even when that slice's raw error rate looks unremarkable next to a noisier one. Slicing becomes a fairness analysis the moment the slice in question is a protected group and the disparity carries real cost.


Small slices lie — check the support before you react

The most common error-analysis mistake is over-reacting to a tiny slice. "Group X has 40% error!" means nothing if group X has 5 examples — that's 2 errors, pure noise. Always report the slice size alongside its error rate, put a confidence interval on the rate (a 40% error on n=5 might really be anywhere from 5% to 85%), and set a minimum-support threshold (say, ignore slices under 30–50 examples) before drawing conclusions. A large slice with a modestly elevated error rate usually matters more than a tiny slice with a scary-looking one.


The sharper root-cause taxonomy

"Data / feature / distribution" is a good start, but name the fuller set so you can match a fix to each: label noise (the ground truth is wrong), data scarcity (too few examples of this pattern), distribution shift (production differs from training), feature blindness (the inputs can't even represent the distinction), annotation ambiguity (humans genuinely disagree, so no model can be "right"), a preprocessing bug (a pipeline error corrupts this slice), or a threshold/calibration issue (the model ranks fine but the cutoff is wrong for this group). Each points to a different fix — collecting more data won't cure a calibration bug or annotation ambiguity.


Slice false positives and false negatives separately

Don't lump all errors together — FPs and FNs usually have different causes and different costs. In fraud, the FNs (missed fraud) might cluster in a new merchant category while the FPs (false alarms) cluster in high-velocity legitimate users — two unrelated problems needing two different fixes. And their business costs differ (a missed fraud vs an annoyed customer). Always build the error breakdown twice, once for each error type.


Comparing two models with error analysis, not just their scores

When two models tie on the aggregate metric, error analysis is how you pick between them: compare their confusion matrices to see which classes each one fails on, compare their critical-segment slices, check whether their errors are high-confidence (confidently wrong) or genuinely uncertain, and check the correlation between their error sets. If the two models are wrong on different examples, their errors are uncorrelated and they are strong candidates to ensemble — combining them can cancel out each other's mistakes. If they are wrong on the same examples, ensembling buys you little.


From notebook to monitor

Error analysis shouldn't be a one-time notebook exercise you do before launch and forget. The slices you discover — 3-word commands, code-switching, new merchant categories — should become monitored production slices, tracked continuously so you catch when a slice's error rate creeps up after deploy. A finding that lives only in a notebook decays; a finding wired into monitoring keeps paying off.


The human side: labels and adjudication

When errors trace to *annotation ambiguity*, the fix is a labeling process, not a model change. Measure inter-annotator agreement — if two humans disagree on a slice, the model can't be blamed for missing it. Set up an adjudication step for disputed cases, update the labeling guidelines to resolve the ambiguity, and accept that some errors are "ambiguous but acceptable" — genuinely reasonable answers the rigid label just didn't credit. Not every error is a bug.


Prove the fix with a counterfactual check, and prioritise with the real formula

Before claiming a fix works, run an ablation: remove the suspicious feature, or add the targeted data, or apply the augmentation — then compare the *slice* metric before and after, not just the aggregate. And prioritise slices with more than a raw error count: impact = slice volume × error rate × cost per error × fix feasibility. A big, expensive, easily-fixed slice beats a small, cheap, mysterious one — the count of total errors alone will point you at the wrong work.

Key points

Takeaway

Aggregate metrics tell you that a problem exists — error slicing by confidence, subgroup, and input type tells you which specific subpopulation has the problem — and targeting 200 examples of the hardest error category almost always moves more metric than any architectural change.

Recap

Check your understanding

Q1. Your NLP classifier has 88% overall accuracy but stakeholders are unhappy. How do you diagnose what is wrong?

Q2. You sample 100 FPs from a fraud detection model and find that 60% involve transactions from a new merchant category launched 2 months ago. Which two actions are appropriate? Select two.

Q3. You have two models both with F1=0.82. How do you choose which to deploy using error analysis?

Q4. What is the difference between error slicing and subgroup fairness analysis? When does one become the other?

Q5. In your error slicing, one segment shows a 50% error rate versus 8% overall — but that segment has only 6 examples (3 of 6 wrong). What's the right move?

Q6. You've decided which error slice to fix first. Which prioritisation best reflects real-world impact?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →