I'm learning machine learning using the scikit-learn library and I was puzzled when I see the code from Scikit-learn tutorial
It has the following code:
import numpy as np
from sklearn.impute import SimpleImputer
imp = SimpleImputer(missing_values=np.nan, strategy='mean')
imp.fit([[1, 2], [np.nan, 3], [7, 6]])
X = [[np.nan, 2], [6, np.nan], [7, 6]]
print(imp.transform(X))
From what I understand, imputer is used to fill in the missing values, and that it uses some strategy like mean, median or mode. But I don't understand what these 3 lines of code are doing
imp.fit([[1, 2], [np.nan, 3], [7, 6]])
X = [[np.nan, 2], [6, np.nan], [7, 6]]
print(imp.transform(X))
Why does it fit a matrix with np.nan ? And how these fitting affect the imp.transform(X)?