【问题标题】:GridSearchCV not getting std scores on the cv_results dictionary?GridSearchCV 没有在 cv_results 字典上获得标准分数?
【发布时间】:2021-05-12 09:39:53
【问题描述】:

直到最近,我一直在使用 GridSearchCV 通过 here 中的操作来获取交叉验证的标准分数

所以基本上是这样做的

grid_search.cv_results_['std_test_score'][grid_search.best_index_]

但现在我收到一个关键错误,告诉我“std_test_score”不是关键。

这就是我调用 GridSearchCV 函数的方式

splitter = StratifiedKFold(n_splits=5, shuffle=True, random_state=11)


scoring_functions = {'mcc': make_scorer(matthews_corrcoef), 'accuracy': make_scorer(accuracy_score), 
                     'balanced_accuracy': make_scorer(balanced_accuracy_score)}

grid_search = GridSearchCV(pipeline, param_grid=grid, scoring=scoring_functions, n_jobs=-1, cv=splitter, refit='mcc')

【问题讨论】:

    标签: python-3.x scikit-learn standard-deviation gridsearchcv


    【解决方案1】:

    来自the documentationcv_results_属性说明:

    对于多指标评估,所有评分者的分数都可以在 cv_results_ 字典中以该评分者姓名 ('_<scorer_name>') 结尾的键中获得,而不是上面显示的 '_score'。 ('split0_test_precision'、'mean_train_precision' 等)

    您可以通过grid_search.cv_results_.keys() 自行轻松到达那里,看看有什么可用的。它应该是例如grid_search.cv_results_['std_test_mcc'].

    【讨论】:

    • 是的,我刚刚完成了对密钥的调查,并来到这里编写解决方案,但你打败了我。谢谢!
    猜你喜欢
    • 2018-08-12
    • 2021-02-16
    • 2020-05-03
    • 2022-01-27
    • 2017-03-29
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多