Skip to content

Instantly share code, notes, and snippets.

@vanbrands
Last active July 30, 2020 03:40
Show Gist options
  • Save vanbrands/190947d2e042201010001660036eca50 to your computer and use it in GitHub Desktop.
Save vanbrands/190947d2e042201010001660036eca50 to your computer and use it in GitHub Desktop.
from sklearn.preprocessing import KBinsDiscretizer
from sklearn.model_selection import RandomizedSearchCV
search_space = {
'preprocessing__binfeatures__n_bins': [10, 20],
'model__n_estimators': [500, 1000, 2000],
'model__class_weight': ['balanced', 'balanced_subsample']
}
preprocessing = ColumnTransformer(transformers=[
('binfeatures', KBinsDiscretizer(), ['numerical_feature'])
])
pipeline = Pipeline(steps=[
('preprocessing', preprocessing),
('model', RandomForestClassifier())
])
search = RandomizedSearchCV(pipeline, search_space, cv=5)
search.fit(x, y)
search.best_estimator_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment