thebench.bio #1 Ecosystem for the Bio-Tech Industry
All Machine Learning questions

Question 17 of 20 Intermediate Practical

How would you handle missing feature values before training a model?

Short answer

First find out why values are missing, because the reason can itself be predictive. Then either impute inside the cross-validation pipeline, optionally adding missingness indicators, or use a model such as histogram gradient boosting that handles missing values natively. Never fill gaps using the whole dataset before splitting.

Why

Missing values in biomedical tables are rarely random. A lab test missing because the clinician did not think it was needed tells the model something about the patient. Dropping incomplete rows can remove most of a dataset and bias it toward healthier or better-documented patients. scikit-learn offers SimpleImputer for mean, median, most-frequent or constant filling, and IterativeImputer, which models each feature from the others.

Both have an add_indicator option that appends a column marking which values were missing, preserving that signal. HistGradientBoostingClassifier and Regressor learn at each split which side missing values should go to, so they need no imputation.

How to work it through

  1. Tabulate missingness per feature and per outcome group to see how much is missing and whether it relates to the outcome.
  2. Ask the data owners how missing values arise for the main features.
  3. Drop features that are almost entirely missing unless the missingness itself is meaningful.
  4. Put the imputer inside a Pipeline so its statistics are learned from training folds only.
  5. Compare a simple imputer with indicators against a native missing-value model under the same cross-validation.
  6. Check that the deployment data will have the same missingness pattern before relying on the indicator features.

An example

A model predicts 30-day readmission from 40 lab features for 6,000 patients. Lactate is missing in 55 percent of records and is missing far more often in low-risk patients. Dropping incomplete rows would leave 1,900 patients.

A pipeline with median imputation and indicators reaches cross-validated AUC 0.74, and histogram gradient boosting with native handling reaches 0.75. The lactate indicator ranks high, which the team reports as an ordering pattern rather than a lab effect, and they check that the new hospital orders lactate in a similar way.

Where the answer stops holding

Indicator features encode care processes, which change between sites and over time, so a model that leans on them can fail when ordering habits change. Single imputation understates uncertainty for inference, which matters for coefficients and p-values more than for prediction. IterativeImputer is still marked experimental in scikit-learn and must be explicitly enabled before import.

A strong answer covers

  • Understand why values are missing
  • Impute inside the pipeline, not before splitting
  • Missingness indicators keep informative gaps
  • Native handling in histogram gradient boosting
  • Check deployment missingness matches training

Common mistakes

  • Filling missing values with the whole-dataset mean before cross-validation
  • Dropping all incomplete rows and reporting performance on a biased subset
  • Encoding missing as zero when zero is a valid measured value