Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# 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):
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