Skip to content

Instantly share code, notes, and snippets.

@yashprakash13
Created December 26, 2021 16:47
Show Gist options
  • Save yashprakash13/2fdb20900538d92f5d73817bd8c67d01 to your computer and use it in GitHub Desktop.
Save yashprakash13/2fdb20900538d92f5d73817bd8c67d01 to your computer and use it in GitHub Desktop.
# Do grid search
from sklearn.model_selection import GridSearchCV
rf_classifier = RandomForestClassifier(random_state=0)
rf_model_pipeline = Pipeline(steps=[
('preprocessing', columns_transformer),
('rf_model', rf_classifier),
])
params_dict = {'rf_model__n_estimators' : np.arange(5, 100, 1), 'rf_model__criterion': ['gini', 'entropy'], 'rf_model__max_depth': np.arange(10, 200, 5)}
grid_search = GridSearchCV(rf_model_pipeline, params_dict, cv=10, n_jobs=-1)
grid_search.fit(X_train, y_train)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment