Created
November 18, 2020 00:31
-
-
Save tiaplagata/3fe3c4093dcf1571a2f3e53033d5ee25 to your computer and use it in GitHub Desktop.
FunctionTransformer in 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.preprocessing import FunctionTransformer | |
# The function we want to convert to a class for our pipeline | |
def transform_yes_no(X): | |
X['international plan'] = X['international plan'].apply(lambda x: 1 if x.lower() == 'yes' else 0) | |
X['voice mail plan'] = X['voice mail plan'].apply(lambda x: 1 if x.lower() == 'yes' else 0) | |
return X | |
# Convert to class for pipeline | |
YesNoTransformer = FunctionTransformer(transform_yes_no) | |
# Define the pipeline | |
pipeline = Pipeline(steps= [ | |
("TransformCategorical", YesNoTransformer), | |
("SMOTE", SMOTE()), | |
("GradientBooster", GradientBoostingClassifier()) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment