Created
September 2, 2018 02:05
-
-
Save discdiver/a323e62dcae117d5e3afcad8e3750a48 to your computer and use it in GitHub Desktop.
An example of using Category Encoders.
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 packages | |
import numpy as np | |
import pandas as pd | |
import category_encoders as ce | |
# make some data | |
df = pd.DataFrame({ | |
'color':["a", "b", "a", "c"], | |
'outcome':[1, 2, 3, 2]}) | |
# split into X and y | |
X = df.drop('outcome', axis = 1) | |
y = df.drop('color', axis = 1) | |
# instantiate an encoder - here we use Binary() | |
ce_binary = ce.BinaryEncoder(cols = ['color']) | |
# fit and transform and presto, you've got encoded data | |
ce_binary.fit_transform(X, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment