Imputation Methods: Mean, Median, KNN, MICE Compared
Imputation replaces missing values with estimates so you can keep the row instead of dropping it. The four methods you'll actually meet in practice — mean/median fill, K-nearest-neighbors, and MICE (multiple imputation by chained equations) — trade off bias, honesty about uncertainty, and effort very differently.
Quick answer: Mean/median imputation is fast but shrinks variance and flattens correlations — acceptable only for low missingness in unimportant columns. KNN imputation borrows values from similar rows and preserves relationships better. MICE builds a regression model per column and, run properly as multiple imputation, is the statistical gold standard for MAR data. Never impute your target variable.
How do the main imputation methods compare?
The core trade-off: simple methods distort your data's distribution, while sophisticated methods cost setup time and compute. This table summarizes the practical differences for a numeric column with moderate missingness:
| Method | Bias in the mean | Variance distortion | Preserves correlations? | Difficulty |
|---|---|---|---|---|
| Mean fill | None under MCAR; biased under MAR/MNAR | Severe shrinkage | No — pulls them toward 0 | Trivial |
| Median fill | Same as mean, robust to outliers | Severe shrinkage | No | Trivial |
| KNN | Low under MAR if features predict the gap | Mild shrinkage | Mostly | Moderate (scaling matters, slow on big data) |
| MICE | Low under MAR | Honest — adds noise back in | Yes | Highest (iterative, needs pooling across imputations) |
Why does mean imputation shrink variance?
Because every imputed cell gets the exact same value — the center of the distribution. Real missing values would have been spread out; replacing them all with one number piles probability mass at the mean, so the column's standard deviation drops and its histogram grows a spike. Correlations weaken too, since the imputed points form a flat horizontal line in any scatterplot.
Concretely: impute 20% of a column with its mean and the variance of that column falls by roughly 20% — which narrows confidence intervals and inflates significance artificially. Your analysis becomes more confident precisely because you invented data with zero spread. This is the main reason mean imputation is fine for a quick ML baseline but risky for statistical inference.
When should I use mean or median fill anyway?
When missingness is small (under ~5%), the column is a minor predictor, and you need something fast and deterministic — typically inside an ML pipeline where predictive accuracy, not inference, is the goal. Prefer median over mean for skewed columns (income, page views) so outliers don't drag the fill value. And pair the fill with a missingness indicator column so the model can still learn from the gap itself:
import pandas as pd
df['income_missing'] = df['income'].isna().astype(int)
df['income'] = df['income'].fillna(df['income'].median())
More fillna patterns — group-wise fills, forward-fill for time series — are covered in pandas fillna for missing data.
How do KNN and MICE work, without the math?
KNN imputation finds the k rows most similar to the incomplete row on its observed columns, then fills the gap with those neighbors' average. A 40-year-old engineer with a missing salary gets a salary typical of other 40-year-old engineers — not the company-wide mean. It respects relationships between columns, but you must scale features first (otherwise one big-range column dominates the distance), and it gets slow on wide or tall data.
MICE goes further: it fills every column's gaps with a regression model trained on all the other columns, then cycles through the columns repeatedly until the fills stabilize. Crucially, run as multiple imputation it produces several completed datasets with deliberately different random draws, you analyze each, and pool the results. That spread across datasets is what keeps your standard errors honest — single-shot imputation of any kind understates uncertainty. Under MAR missingness, pooled MICE estimates are unbiased, which is why it's the default in clinical and social-science research.
When should you NOT impute?
Three situations where imputation is the wrong move. First and most important: never impute the target variable in supervised learning or the outcome in a study — you'd be training the model on answers you made up, and errors in the imputation leak straight into your labels. Drop those rows instead. Second: when a value is missing because it doesn't exist (a "spouse_age" for single people) — that's structural missingness, and the fix is modeling or encoding, not filling. Third: when missingness is heavy (over ~40–50%) in a column of real importance — at that point the imputation model is mostly fiction, and dropping the column or collecting more data is more honest.
Also remember imputation cannot rescue MNAR data: if high values are missing because they're high, every method above will still underestimate them. And whatever you choose, fit the imputer on training data only, then apply it to test data — imputing before the split leaks information.
For the decision process across dropping vs filling, see deletion vs imputation and the broader missing data handling guide.
Pro Tip: Whatever method you pick, plot the column's distribution before and after imputing. A new spike at the mean, a flattened histogram, or a correlation that jumped or collapsed is your early-warning system that the imputation changed the story your data tells.
← Back to Data Analysis Tips