Created
May 11, 2022 17:37
-
-
Save cnmoro/fe6ccfc1859b5a1bd969e1d3a73be387 to your computer and use it in GitHub Desktop.
Extract WOE Encoder Mappings
This file contains hidden or 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 category_encoders as ce | |
categoric_features = ['a', 'b', 'c'] | |
woe_encoder = ce.WOEEncoder(cols=categoric_features) | |
woe_encoder.fit(X[categorics], y) | |
def get_woe_value(feature): | |
for map in woe_encoder.ordinal_encoder.mapping: | |
if map['col'] == feature: | |
return dict(map['mapping']) | |
for cat in categoric_features: | |
print(f"{cat} mapping:") | |
feature_mapping_original_ordinal = get_woe_value(cat) | |
feature_mapping_ordinal_woe = dict(woe_encoder.mapping[cat]) | |
for conteudo_original, ordinal_encoded_value in feature_mapping_original_ordinal.items(): | |
print(f"Original value: {conteudo_original} | Encoded WOE value: {feature_mapping_ordinal_woe[ordinal_encoded_value]}") | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment