# How does imputation work? I'm struggling to understand it

I have a short question. I am implementing Scikit-Learn in Typescript and currently blocked at understanding & implementing imputer (mean and regression strategies).

Based on the example given on Scikit-Learn page, http://scikit-learn.org/stable/modules/preprocessing.html#imputation

>>> import numpy as np
>>> from sklearn.preprocessing import Imputer
>>> imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
>>> imp.fit([[1, 2], [np.nan, 3], [7, 6]])
Imputer(axis=0, copy=True, missing_values='NaN', strategy='mean', verbose=0)
>>> X = [[np.nan, 2], [6, np.nan], [7, 6]]
>>> print(imp.transform(X))
[[ 4.          2.        ]
[ 6.          3.666...]
[ 7.          6.        ]]


How does imputation against np.nan in [[np.nan, 2], [6, np.nan], [7, 6]] work?

• Could you please explain it to me how it works? I would appreciate any equations and background knowledge that I need to understand this.
The Imputer is just calculating the mean for each column when fit is called. So column 1 has mean (1+7)/2 = 4 and column 2 has mean (2+3+6)/3 = 3.666....
The transform function just fills in the NaN fields with the column's mean value.