📜  网格搜索python代码示例

📅  最后修改于: 2022-03-11 14:47:08.308000             🧑  作者: Mango

代码示例1
from sklearn.model_selection import GridSearchCV

params = {
    'n_estimators': [5, 10, 20],
    'max_depth': [1, 5, 10],
}

grid_search = GridSearchCV(RandomForestRegressor(), param_grid=params, n_jobs=-1)
grid_search.fit(X_train, y_train)
score = np.round(grid_search.score(X_test, y_test), 3)
print(f"Best random forest classifier score: {score}")
grid_search.best_estimator_, grid_search.best_params_