Last active
November 17, 2020 03:02
-
-
Save tiaplagata/3b559bda860b02d61260b8be8b7f46f8 to your computer and use it in GitHub Desktop.
Custom Classes for Pipeline
This file contains hidden or 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
from sklearn.ensemble import BaseEnsemble | |
# Build custom classes to add to the pipeline | |
class SelectColumnsTransformer(BaseEnsemble): | |
def __init__(self, columns=None): | |
self.columns = columns | |
def transform(self, X, **transform_params): | |
cpy_df = X[self.columns].copy() | |
return cpy_df | |
def fit(self, X, y=None, **fit_params): | |
return self | |
class Transform_Categorical(BaseEnsemble): | |
def transform(self, X, y=None, **transform_params): | |
try: | |
X['international plan'] = X['international plan'].apply(self.yes_no_func) | |
X['voice mail plan'] = X['voice mail plan'].apply(self.yes_no_func) | |
except: | |
pass | |
return X | |
def fit(self, X, y=None, **fit_params): | |
return self | |
@staticmethod | |
def yes_no_func(x): | |
return 1 if x.lower() == 'yes' else 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment