Handling missing values

When to remove and when to impute, and why the imputation is computed from the training data only.

20 minutesData analysis

What you will learn

  • Choosing a suitable way to handle missing values
  • Avoiding data leakage during imputation

Causes of missing values: an entry error, an unanswered question, a broken device. The options: remove the rows (if the missing values are few and random), remove the column (if most of it is missing), or imputation with the mean or median (for numbers) or the most frequent value (for categories).

The median is better than the mean when there are outliers. Model-based imputation is more accurate but more complex.

An important rule: compute the imputation value from the training data only and then apply it to the test data, otherwise information from the test data leaks into training.

Implementation steps with the tool

  1. Orange: Impute (a method for each column).
  2. KNIME: Missing Value.
  3. WEKA: the ReplaceMissingValues filter.
  4. The data processing lab: compare the table before and after.

Quick review question

An income column has large outliers and 5% missing values. What do you impute with?

Tools

Try it in the lab