Skip to content

Instantly share code, notes, and snippets.

@finlytics-hub
Created July 6, 2020 12:35
Show Gist options
  • Save finlytics-hub/8b58546d2fc5333b6fbaad79f4919540 to your computer and use it in GitHub Desktop.
Save finlytics-hub/8b58546d2fc5333b6fbaad79f4919540 to your computer and use it in GitHub Desktop.
Practical demonstration of SimpleImputer
# import the required library
from sklearn.impute import SimpleImputer
# define imputer
imputer = SimpleImputer(strategy='mean') # other options include: median, most_frequent, constant
# fit on the training dataset
imputer.fit(X_train)
# transform the training dataset (don't forget to transform the test dataset as well)
X_train_clean = pd.DataFrame(imputer.transform(X_train), columns = X_train.columns, index = X_train.index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment