# 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