我正在尝试使用随机森林解决我的问题(以下是波士顿数据集的示例代码,不是我的数据)。我计划使用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_