Skip to content

Instantly share code, notes, and snippets.

@joshreini1
Created August 30, 2022 19:43
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 joshreini1/1c3cb3a733a1cd1f81f937c8f150f009 to your computer and use it in GitHub Desktop.
Save joshreini1/1c3cb3a733a1cd1f81f937c8f150f009 to your computer and use it in GitHub Desktop.
Transformer to prevent column leakage of test
class comprehensive_features_custom(BaseEstimator, TransformerMixin):
def __init__(self, comprehensive_features):
self.comprehensive_features = comprehensive_features
def fit(self, X, y = None):
return self
def transform(self, X):
X_post = X.reindex(labels=comprehensive_features, axis=1)
return X_post
set_comprehensive_features = comprehensive_features_custom(comprehensive_features)
#comprehensive preprocessing pipe
comprehensive_preprocessing = Pipeline([
('combined_preprocessing',combined_preprocessing),
('set_comprehensive_features',set_comprehensive_features)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment