728x90
반응형
코드
from sklearn.model_selection import GridSearchCV
params = {
'n_estimators':[100],
'max_depth' : [6,8,10.,12],
'min_samples_leaf' : [8,12, 18],
'min_samples_split' : [8,16, 20]
}
rf_clf = RandomForestClassifier(random_state=0)
model = rf_clf
grid_cv = GridSearchCV(model, param_grid=params, cv=2, n_jobs=-1)
grid_cv.fit(X_train, y_train)
print('Best parameter:\n', grid_cv.best_params_)
print('Highest accuracy: {0:.4f}'.format(grid_cv.best_score_))
출처: 파이썬 머신러닝 완벽가이드 p220
728x90
반응형