Skip to content

Instantly share code, notes, and snippets.

@finlytics-hub
Created July 7, 2020 09:05
Show Gist options
  • Save finlytics-hub/45d6ee85820669b47d2663929731e39c to your computer and use it in GitHub Desktop.
Save finlytics-hub/45d6ee85820669b47d2663929731e39c to your computer and use it in GitHub Desktop.
Practical demonstration of SimpleImputer
# import the required library
from sklearn.impute import KNNImputer
# define imputer
imputer = KNNImputer() # you might want to try different n_neighbors parameters. Default is 5
# 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