Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Created January 28, 2020 14:03
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 lakshay-arora/27a0f5682418941a9ef70efbd7f698f6 to your computer and use it in GitHub Desktop.
Save lakshay-arora/27a0f5682418941a9ef70efbd7f698f6 to your computer and use it in GitHub Desktop.
# import the BaseEstimator
from sklearn.base import BaseEstimator
# define the class OutletTypeEncoder
# This will be our custom transformer that will create 3 new binary columns
# custom transformer must have methods fit and transform
class OutletTypeEncoder(BaseEstimator):
def __init__(self):
pass
def fit(self, documents, y=None):
return self
def transform(self, x_dataset):
x_dataset['outlet_grocery_store'] = (x_dataset['Outlet_Type'] == 'Grocery Store')*1
x_dataset['outlet_supermarket_3'] = (x_dataset['Outlet_Type'] == 'Supermarket Type3')*1
x_dataset['outlet_identifier_OUT027'] = (x_dataset['Outlet_Identifier'] == 'OUT027')*1
return x_dataset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment