小编Muh*_*mad的帖子

随机森林超参数调整scikit-learn使用GridSearchCV

我正在尝试使用随机森林来解决我的问题(下面是波士顿数据集的示例代码,而不是我的数据).我打算GridSearchCV用于超参数调整,但不同参数的值范围应该是多少?我怎么知道我选择的范围是正确的?

我正在互联网上阅读它并且有人建议在第二次网格搜索中尝试"放大"最佳值(例如,如果它是10则尝试[5,20,50]).

这是正确的方法吗?我应该对随机森林所需的所有参数使用这种方法吗?这种方法可能会错过"好"的组合,对吧?

import numpy as np
from sklearn.grid_search import GridSearchCV
from sklearn.datasets import load_digits
from sklearn.ensemble import RandomForestRegressor
digits = load_boston()
X, y = dataset.data, dataset.target
model = RandomForestRegressor(random_state=30)
param_grid = { "n_estimators"      : [250, 300],
           "criterion"         : ["gini", "entropy"],
           "max_features"      : [3, 5],
           "max_depth"         : [10, 20],
           "min_samples_split" : [2, 4] ,
           "bootstrap": [True, False]}
grid_search = GridSearchCV(clf, param_grid, n_jobs=-1, cv=2)
grid_search.fit(X, y)
print grid_search.best_params_
Run Code Online (Sandbox Code Playgroud)

python random-forest scikit-learn grid-search

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

grid-search ×1

python ×1

random-forest ×1

scikit-learn ×1