【发布时间】:2018-06-17 07:58:42
【问题描述】:
我正在尝试使用 GridSearchCV 调整 n_estimators 的 RandomForestClassifier。但我收到类型错误提示 -> TypeError: get_params() missing 1 required positional argument: 'self'
代码:
from sklearn.grid_search import GridSearchCV
from sklearn.ensemble import RandomForestClassifier
n_trees = list(range(10,110,10))
print(n_trees)
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
param_grid = dict(n_estimators=n_trees)
print(param_grid)
{'n_estimators': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]}
grid = GridSearchCV(RandomForestClassifier, param_grid, cv=5, scoring='roc_auc')
grid.fit(X,y) <--- Getting error at this cell
【问题讨论】:
-
你试过我的解决方案了吗?
-
您需要传递分类器而不是基类作为估计器。所以将
()添加到基类,即RandomForestClassifier()
标签: python pandas scikit-learn