Created
July 7, 2020 09:05
-
-
Save finlytics-hub/45d6ee85820669b47d2663929731e39c to your computer and use it in GitHub Desktop.
Practical demonstration of SimpleImputer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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