Missing Data Imputation
Deleting every row with a gap can throw away most of a dataset, so most machine-learning pipelines fill gaps in in a principled way instead — the right method depends on why the data is missing in the first place.
Prerequisites: Missing Data and Forward Fill, Outlier Detection and Winsorization
A cross-sectional stock model with 60 fundamental features will almost never have all 60 filled in for every company — small caps skip disclosures, new listings lack history, some ratios are undefined when a denominator is zero. Deleting every row with any gap can wipe out most of the universe. Imputation fills the gap with an estimate instead, and which estimate is defensible depends on why the value is missing, not just that it's missing.
The three fixes, roughly in order of sophistication, are: fill with a summary statistic (mean, median, or a sensible constant), fill using a model that predicts the missing feature from the other features, or add multiple plausible fills and average over them. The best choice depends on whether the missingness itself carries information.
Why the mechanism matters
Statisticians split missingness into three cases. Data missing completely at random — a data feed randomly dropped a value for reasons unrelated to anything — can be filled safely with something like the column mean, since the gap carries no signal. Data missing at random conditional on other features — a company's leverage ratio is missing specifically because it has no debt, which is itself visible from other fields — needs a fill that uses those other fields, typically a regression or k-nearest-neighbors imputer trained to predict the missing column from the rest. Data missing not at random — a company stopped reporting a metric right before a restatement — means the missingness itself is the signal, and no fill value substitutes for that; the better move is often a separate "was this missing" indicator feature rather than trying to guess the value at all.
Worked example
A dataset of 4,000 small-cap stocks has a "days-sales-outstanding" feature missing for 380 of them, mostly newly listed companies with under two quarters of reporting history. Filling those 380 gaps with the column mean (48 days) would implicitly claim these new listings collect receivables at an average pace — plausible, but unverified. Filling instead with a k-nearest-neighbors imputer (k=5), matched on sector, revenue size, and listing age, produces fills ranging from 22 to 71 days depending on each company's actual peer group — closer to what a real analyst would guess company-by-company, and it preserves the cross-sectional spread the mean fill would have flattened out.
What this means in practice
For tree-based models (random forests, gradient boosting), a simple approach is often enough: fill with an out-of-range constant (like -999) and let the tree learn to split on "missing" as its own bucket, since trees can isolate that value without needing it to be a plausible number. Linear models and neural networks are more sensitive, because an out-of-range fill directly distorts a dot product or activation, so a model-based imputer or an explicit missingness indicator is usually worth the extra step.
Always fit the imputer (the column means, the KNN model, whatever it is) only on the training fold and apply it unchanged to validation and test folds — refitting it on the full dataset lets test-set values leak into how training-set gaps get filled.
Related concepts
Practice in interviews
Further reading
- Little & Rubin, Statistical Analysis with Missing Data (3rd ed.)
- Van Buuren, Flexible Imputation of Missing Data (2nd ed.)