SimpleImputer

noun

say it: “SIM-pul im-PYOO-ter” /ˈsɪmpəl ɪmˈpjutər/

A scikit-learn tool that fills in missing values in each column with one value learned from the training data, such as the median.

What is SimpleImputer?

SimpleImputer is scikit-learn's tool for filling missing values: fit() learns one value per column from the training rows, such as the median (strategy="median") or the most common value, and transform() fills the gaps with it. Inside a pipeline, the test rows never shape what it learns.

import numpy as np
from sklearn.impute import SimpleImputer
ages = [[2], [4], [np.nan], [10]]    # years; one is missing
print(SimpleImputer(strategy="median").fit_transform(ages).ravel())   # [ 2.  4.  4. 10.]

In a sentence

  • “Putting the SimpleImputer in the pipeline meant the test rows never shaped its median.”
  • “The SimpleImputer filled each missing age with the training median of 4 years.”

Level: Journeyman · More Python terms at this level

Updated