Created
March 25, 2020 11:10
-
-
Save MaxHalford/f55d4387f50d925488b11729d1010a51 to your computer and use it in GitHub Desktop.
creme target encoding
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
>>> from creme import feature_extraction | |
>>> from creme import stats | |
>>> X = [ | |
... {'place': 'Taco Bell', 'revenue': 42}, | |
... {'place': 'Burger King', 'revenue': 16}, | |
... {'place': 'Burger King', 'revenue': 24}, | |
... {'place': 'Taco Bell', 'revenue': 58}, | |
... {'place': 'Burger King', 'revenue': 20}, | |
... {'place': 'Taco Bell', 'revenue': 50} | |
... ] | |
>>> agg = feature_extraction.TargetAgg( | |
... by='place', | |
... how=stats.Mean() | |
... ) | |
>>> for x in X: | |
... print(agg.transform_one(x)) | |
... y = x.pop('revenue') | |
... agg = agg.fit_one(x, y) | |
{'target_mean_by_place': 0.0} | |
{'target_mean_by_place': 0.0} | |
{'target_mean_by_place': 16.0} | |
{'target_mean_by_place': 42.0} | |
{'target_mean_by_place': 20.0} | |
{'target_mean_by_place': 50.0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment