from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
from sklearn.ensemble import RandomForestClassifier
grid_search = GridSearchCV(
estimator=RandomForestClassifier(random_state=42, n_jobs=-1),
param_grid={
'n_estimators': [200, 400],
'max_depth': [None, 10, 20],
'min_samples_leaf': [1, 3, 5],
},
scoring='roc_auc',
cv=5,
n_jobs=-1,
verbose=1,
)
randomized_search = RandomizedSearchCV(
estimator=RandomForestClassifier(random_state=42, n_jobs=-1),
param_distributions={
'n_estimators': [200, 300, 400, 500],
'max_depth': [None, 8, 12, 16, 24],
'min_samples_split': [2, 5, 10],
'min_samples_leaf': [1, 2, 4],
},
n_iter=15,
scoring='roc_auc',
cv=5,
n_jobs=-1,
random_state=42,
)