Back to Machine Learning

MACHINE LEARNING · QUESTION 57

How do you handle missing data in a machine-learning dataset?

On this page
Intermediate 4 min read
Interview-ready answerThe concise version to remember

I first determine why values are missing and whether the pattern is related to the target, process, or user group. Then I compare dropping records or fields, simple or model-based imputation, and an explicit missingness indicator. Fit imputation only on training data, preserve meaningful missingness, and evaluate by relevant segments because the absence itself can carry signal or bias.

LET'S MAKE IT SIMPLE

First, the idea in plain English

A blank value can mean different things: a sensor failed, a user skipped a question, or the information does not apply. Replacing every blank with one number may hide those differences. The handling method should reflect how the data was collected and what will happen when the model receives new records.

A USEFUL COMPARISON

Picture it this way

A missing temperature reading could mean a broken thermometer or that nobody took a measurement. Those are different situations even though both appear blank. Before filling the blank, find out why it is missing and whether the reason matters.

FOLLOW THE JOURNEY

Investigate missingness before selecting an imputation strategy

Show missingness diagnosis, training-only imputation, indicators, and segment checks.

Investigate missingness before selecting an imputation strategyShow missingness diagnosis, training-only imputation, indicators, and segment checks.Data-preparation flow
01Profile missingnessMeasure which fields and populations have missing values and when.
02Choose treatmentCompare deletion, imputation, indicators, or source correction.
03Fit within trainingEstimate imputation values using training data only.
04Validate by segmentCheck quality and coverage for groups with different missingness.

This simplified visual highlights the main relationships. In practice, the exact design depends on the requirements; An aggregate metric can hide uneven impact.

Data profiling reveals missingness patterns, a chosen imputer is fitted on training records, optional indicators are created, and the pipeline is evaluated by segment.

How to read this visual
This simplified visual highlights the main relationships. In practice, the exact design depends on the requirements; An aggregate metric can hide uneven impact.

UNDER THE HOOD

How it works, step by step

01

Profile missingness

Measure which fields and populations have missing values and when.

Why it matters: The cause can be informative or reveal a collection problem.

02

Choose treatment

Compare deletion, imputation, indicators, or source correction.

Why it matters: Different mechanisms create different bias and information loss.

03

Fit within training

Estimate imputation values using training data only.

Why it matters: Held-out statistics must not influence model fitting.

04

Validate by segment

Check quality and coverage for groups with different missingness.

Why it matters: An aggregate metric can hide uneven impact.

OUTSIDE THE TEXTBOOK

A practical example

An equipment-failure model has missing vibration readings during network outages. The team distinguishes outages from sensors that do not support the measurement, adds a missingness flag, and imputes using training-only statistics. It also checks whether outage patterns vary by factory before trusting the prediction.

GO A LITTLE DEEPER

Technical details that matter

  • Missing completely at random, at random conditional on observed data, and not at random describe different missingness assumptions.
  • Missingness indicators can help but may encode process or demographic proxies.
  • At inference, unseen categories and fully missing columns need defined behavior.

MAKE A GOOD CHOICE

When is this useful?

  • Preparing tabular data with incomplete measurements.
  • Diagnosing collection or pipeline reliability issues.
  • Assessing whether missingness creates unequal coverage or bias.
Consider the alternative

If missingness is a source-system defect, fix ingestion rather than masking it with imputation. Some models support missing values natively, but their behavior still needs validation.

WATCH OUT FOR

Common misunderstandings

  • Replacing every missing value with zero without checking meaning.
  • Imputing before splitting and leaking validation statistics.
  • Dropping records that disproportionately represent a relevant group.

REAL-WORLD TRADE-OFFS

Limitations and failure cases

  • Imputation creates estimates, not recovered truth.
  • Missingness patterns may change in production.
  • Complex imputation can add instability and operational burden.

WHAT TO REMEMBER

Key takeaways

  1. 1Understand why values are missing before choosing a method.
  2. 2Fit learned imputation only on training data.
  3. 3Evaluate coverage and behavior across affected segments.

PRACTICE THE FOLLOW-UP

What might an interviewer ask next?

When would you add a missingness indicator?

When the fact that a value is absent may carry information or distinguish a collection failure from a valid absence; check for unwanted proxy effects.

Should you always impute missing values?

No. Some models handle them, and some fields or records should be excluded or corrected. The choice depends on cause, task, and validation evidence.

SAY IT OUT LOUD

How to explain this in an interview

“I first investigate the reason and pattern of missingness, since a blank can reflect a source failure, an inapplicable field, or a meaningful process. Then I compare deletion, imputation, and missingness indicators. Any learned imputation is fitted on training data only, and I check performance and coverage by segment. If the source is broken, fixing it is better than hiding it.”

Continue your learning path

Connect this question to the roadmap topic it supports.

Open roadmap topic