Created
April 29, 2020 13:38
-
-
Save cereniyim/5d1c115388468c257320c0b05b39620e to your computer and use it in GitHub Desktop.
constant imputer function
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
def ImputeWithConstant(train_df, test_df, cols=["taster_name"]): | |
# function to impute taster_name | |
# with 0 stands for "Unknown value" | |
train_df = pd.DataFrame(train_df[cols]) | |
test_df = pd.DataFrame(test_df[cols]) | |
constant_imputer = SimpleImputer(strategy="constant", fill_value=0) | |
constant_imputer.fit(train_df) | |
imputed_train_set = constant_imputer.transform(train_df) | |
imputed_train_df = pd.DataFrame(imputed_train_set, columns=train_df.columns) | |
imputed_test_set = constant_imputer.transform(test_df) | |
imputed_test_df = pd.DataFrame(imputed_test_set, columns=test_df.columns) | |
return imputed_train_df, imputed_test_df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment