Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 120/ 160
06. Feature Engineering & Model Evaluation

Error Analysis & Residual Diagnostics

Slice errors, plot residuals, and find systematic failure modes that metrics hide.

AdvancedError Slices · Residuals3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Error analysis means looking carefully at where a model gets things wrong and why, so you can fix the biggest problems instead of guessing.

Think of it like…

A doctor reviewing test results doesn't stop at an overall health score: they ask which organ systems are failing, in which patients and why, then target treatment where it will help most.

Where you’ve seen it

A price-prediction model has overall RMSE 12.5. Slicing shows new customers (n = 2,000, RMSE 20) and returning customers (n = 8,000, RMSE 9.8). Overall MSE = (2,000 × 400 + 8,000 × 96.04)/10,000 = 156.8 (RMSE 12.5), and the new-customer slice contributes 800,000 / 1,568,320 = 51% of the total squared error while being 20% of rows. A residual plot also shows a mean residual of +18 (under-prediction) for the top 5% highest-value customers, and residual spread growing with predicted value (heteroscedasticity). Reading the 50 worst predictions reveals three causes: 17 are new customers with no history (cold start), 14 have mislabelled prices (data entry errors confirmed by the finance team), 11 involve a product category absent from training, and 8 are genuine outliers. Fixes in priority order: add cold-start features (signup channel, first-session behaviour) which lowers new-customer RMSE from 20 to 16 and overall RMSE to √[(2,000 × 256 + 8,000 × 96.04)/10,000] = 11.3; correct the label errors with a validation rule; add the missing category; and model log(price) to address the funnel-shaped residuals.

Words you’ll hear

Error slice
A subset of data (by segment, range or time) where error behaves differently.
Residual
Observed minus predicted value; its patterns reveal model misspecification.
Heteroscedasticity
Residual variance that changes with the prediction or a feature.
Error taxonomy
A categorised list of failure causes used to prioritise fixes.

Visual diagram

Loading interactive diagram

Theory & deep dive

Slicing and residual diagnostics

Slice the evaluation data by meaningful dimensions (customer type, geography, product, price quantile, time, data source) and compute the metric per slice with counts and confidence intervals. Because MSE combines additively, each slice's share of total squared error is n_s × MSE_s / Σ n × MSE: new customers, with 2,000 rows and MSE 400, contribute 800,000 out of 1,568,320 (51%) despite being 20% of the data. To find slices automatically, fit a shallow decision tree on the absolute residuals (or use slice-finding tools) and read its leaves, and examine intersections. Check that slice differences are statistically meaningful (small slices give noisy estimates) and compare against irreducible noise estimates.

Residual diagnostics for regression: plot residuals against predicted values (a funnel means heteroscedasticity, a curve means missing non-linearity), against each feature and time (trends indicate drift or omitted seasonality), and against the target (regression to the mean). Examine the mean residual by group to detect bias (+18 for high-value customers means systematic under-prediction), use Q-Q plots for normality when intervals matter, check autocorrelation of residuals for time series (Ljung-Box) and look for influential points. For classification, examine the confusion matrix by class and slice, calibration by group (reliability curves per segment), threshold sensitivity per slice and error types (confident wrong predictions are most informative).

Share of error by slice

New: 2,000 × 400 = 800,000. Returning: 8,000 × 96.04 = 768,320. Total = 1,568,320; overall MSE = 156.8, RMSE = 12.5. New customers are 20% of rows but 51% of squared error. Cutting their RMSE to 16 (MSE 256) gives total (512,000 + 768,320) = 1,280,320, overall RMSE = √128.0 = 11.3.

Key takeaway: Slice by segment, compute each slice's share of total error and inspect residuals against predictions, features and time.

Reading failures, root causes and prioritising fixes

Read the worst predictions (for example the 50 largest absolute errors, plus a random sample of mid-sized ones) with the full feature row, raw source data and the model's explanation (SHAP). Categorise each into a taxonomy: label errors or noise (the ground truth is wrong: fix the data pipeline, add validation rules), missing information (the features don't contain the signal: cold-start customers), coverage gaps (a category or period absent from training), data quality (units, duplicates, stale features), leakage or train-serving skew, model limits (non-linearity, interactions) and genuine randomness (outliers no model can predict). In the example, 17 of 50 are cold start, 14 label errors, 11 unseen category and 8 true outliers, which immediately suggests features, data validation and coverage rather than a bigger model.

Prioritise by expected impact: volume × current error × plausible reduction, divided by effort. Compare fixes by re-evaluating the slice and overall metric (new-customer RMSE 20 → 16 lowers overall RMSE from 12.5 to 11.3), and consider risk (a feature that's unavailable at serving time is useless). Data fixes (labels, coverage, features) usually beat model complexity; if the error budget is dominated by irreducible noise, stop. Keep the analysis repeatable: save slice definitions and the taxonomy, add failure cases to a regression test set, track per-slice metrics in monitoring dashboards and re-run after each release or drift event. Include fairness checks (errors by protected group and proxies) and communicate findings with examples and numbers ("20% of rows produce 51% of error; most are customers with no history").

Impact estimate

Cold-start features reduce new-customer RMSE from 20 to 16 (MSE 400 → 256). Overall MSE falls from 156.8 to 128.0 (−18%), RMSE from 12.5 to 11.3. Fixing 14 label errors removes some of the largest residuals without any model change.

Key takeaway: Categorise failures into causes, estimate each fix's impact on the overall metric and keep failure cases as regression tests.

How it works, step by step

Step 1 of 4
Analyst

1. Slice the evaluation data

Compute metrics, counts and intervals by segment and range; calculate each slice's share of total error.

new customers: 20% of rows, 51% of squared error
Key numbers at this step
Check
slice sample sizes

When to use it & trade-offs

What it is

Error analysis looks past aggregate metrics to find where, how and why a model fails. It combines slicing (metrics by segment: new versus returning customers, price bands, regions, devices, time), residual diagnostics (residuals versus predictions, versus features and over time; Q-Q plots; heteroscedasticity and bias by group), worst-case review (reading the highest-error examples), error taxonomies (categorising failures into causes such as label noise, missing features, data quality, rare cases and distribution shift) and prioritisation by impact. For classification, the analogues are per-class and per-slice precision and recall, confusion patterns and calibration by group. The output is a ranked list of concrete fixes, not just a better number.

Why it matters: A single RMSE or AUC says how good the model is overall, not what to do next. Errors are rarely spread evenly: a small segment often produces most of the loss, systematic bias hides in subgroups, and a few mislabelled or leaked rows can distort metrics. Error analysis turns evaluation into an improvement roadmap, catches fairness and reliability problems before users do and often shows that data fixes beat model changes.

When to reach for it

  • After the first baseline model
  • Before deciding what to build next
  • Fairness and reliability reviews

When to avoid or be careful

  • Improving the model without looking at failures
  • Drawing conclusions from tiny slices
  • Ignoring label errors as 'model error'

Error analysis tools

Slice metrics and error shares
Best for: Finding where most error comes from

Strengths: Quantitative; points to priorities.

Watch out: Needs meaningful segment definitions.

Residual plots and group bias checks
Best for: Detecting misspecification and systematic bias

Strengths: Reveal funnels, curvature and drift.

Watch out: Require interpretation.

Manual review of worst cases
Best for: Understanding root causes

Strengths: Finds label errors and missing signals.

Watch out: Time-consuming; small samples.

Interview signals & numbers to know

When this topic comes up

  • “The model is bad for new users”
  • Residual plots
  • Error slices
  • Cold start
  • Label noise

Benchmarks & rules of thumb

51% of squared error -
from 20% of rows (new customers)
12.5 → 11.3 -
overall RMSE after improving the new-customer slice
17 / 14 / 11 / 8 -
worst-50 errors by cause

Common mistakes & follow-ups

Common interview mistakes

  • Using aggregate metrics to decide what to improve.
  • Treating label errors as unfixable model noise.
  • Not saving failure cases for future regression tests.

Likely interviewer follow-ups

  • How would you decide what to improve after training a baseline?
  • What do residual plots tell you?
  • How do you find slices where a model underperforms?
Interview tip: Calculate each slice's share of total error (20% of rows, 51% of error). It turns a vague "the model is weak somewhere" into a clear priority.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Error Analysis & Residual Diagnostics with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Model Explainability with SHAP & LIME
Next topic
Perceptrons & Multi-Layer Perceptrons (MLP)