Skip to content

Instantly share code, notes, and snippets.

@discdiver
Created September 2, 2018 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save discdiver/a323e62dcae117d5e3afcad8e3750a48 to your computer and use it in GitHub Desktop.
Save discdiver/a323e62dcae117d5e3afcad8e3750a48 to your computer and use it in GitHub Desktop.
An example of using Category Encoders.
# 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