Created
April 29, 2020 13:06
-
-
Save cereniyim/d375c41f7eb455402bd9cc266f22f321 to your computer and use it in GitHub Desktop.
ordinal encoder 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 EncodeCategoricalData(train_df, | |
test_df, | |
cols=ordinal_encode_cols): | |
# funtion to create ordinal encoder object and | |
# assigns -1 to the unseen labels of the test set | |
# returns ordinal encoded train and test datasets | |
# respectively | |
ordinal_encoder = OrdinalEncoder(cols=ordinal_encode_cols, | |
return_df=True, | |
handle_unknown="value", | |
handle_missing="return_nan") | |
ordinal_encoder.fit(train_df) | |
ord_encoded_train = (ordinal_encoder | |
.transform(train_df)) | |
ord_encoded_test = (ordinal_encoder | |
.transform(test_df)) | |
return ord_encoded_train, ord_encoded_test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment