【问题标题】:Setting Cross Validation parameter in Grid Search在网格搜索中设置交叉验证参数
【发布时间】:2017-10-07 02:21:20
【问题描述】:

我正在尝试在 GridSearch 中设置 RandomForestClassification

rfc_model = RandomForestClassifier(n_estimators = 5, max_depth = 3 )

gs = grid_search.GridSearchCV(estimator = rfc_model,
                             param_grid = {'n_estimators': [i for i in range(1,52,10)],
                                          "max_depth": [3, 5],
                                          "bootstrap": [True, False],
                                          "criterion": ["gini"]},
                             cv = cross_val_score(rfc_model,X, y, scoring='roc_auc'))

gs.fit(X, y)
gs.grid_scores_
print gs.best_estimator
print gs.best_score_

我得到了错误

TypeError: 'numpy.float64' object is not iterable

显然我正在学习,所以欢迎任何 cmet。

【问题讨论】:

标签: python numpy random-forest grid-search


【解决方案1】:

好的,我找到了问题,我使用了错误的方法(可以调用它的方法吗?)交叉验证,下面的解决方案:

gs = grid_search.GridSearchCV(estimator = model,
                             param_grid = {'n_estimators': [i for i in range(1,52,10)],
                                          "max_depth": [3, 5],
                                          "bootstrap": [True, False],
                                          "criterion": ["gini"]},
                             cv = cross_validation.KFold(n=len(X), n_folds=10), scoring='roc_auc')

【讨论】:

    猜你喜欢
    • 2021-12-11
    • 1970-01-01
    • 2015-09-18
    • 2017-12-29
    • 2013-01-29
    • 2014-01-10
    • 2019-03-30
    • 2017-06-19
    • 2013-10-20
    相关资源
    最近更新 更多