0
$\begingroup$

I have following code, I am not able to understand the difference between use of fit_transform() and transform() method in this case.

In the following code, when I am using fit_transform(X_valid) instead of transform(X_valid) it gives me different outputs.

from sklearn.impute import SimpleImputer

# Imputation
my_imputer = SimpleImputer()
imputed_X_train = pd.DataFrame(my_imputer.fit_transform(X_train))
imputed_X_valid = pd.DataFrame(my_imputer.transform(X_valid))
$\endgroup$
2