如何从GridSearchCV的每一折中获得准确性和f1分数? [英] How to get accuracy and f1-score from each fold in GridSearchCV?

查看:710
本文介绍了如何从GridSearchCV的每一折中获得准确性和f1分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GridSearchCV对象来训练分类器.我设置了5折验证参数搜索,并在调用fit()之后,需要查看每折的验证集的指标,即准确性和f1得分.我该怎么办?

I'm using the GridSearchCV object to train a classifier. I setup 5-fold validation parameter search and after calling fit(), I need to see the metrics for each fold's validation set, namely accuracy and f1-score. How can I do this?

 clf = GridSearchCV(pipeline,
                        param_grid=param_grid, 
                        n_jobs=1, 
                        cv=5,
                        compute_training_score=True)

注意:

  • 我没有要使用的单独测试集,因此我不能仅采用预测结果并使用标准指标功能来进行处理.
  • 使用clf.best_scores_不能提供我想要的信息,而只能提供mean_validation_score及其标准差.

推荐答案

分数位于grid_scores_中,尤其是在cv_validation_scores中:

Scores are located in grid_scores_, in particular in cv_validation_scores:

grid_scores _ :命名元组列表

包含所有参数的分数 param_grid中的组合.每个条目对应一个参数 环境.每个命名元组都具有以下属性:

Contains scores for all parameter combinations in param_grid. Each entry corresponds to one parameter setting. Each named tuple has the attributes:

  • 参数,是 参数设置
  • mean_validation_score,平均得分超过 交叉验证折叠
  • cv_validation_scores,分数列表 每折
  • parameters, a dict of parameter settings
  • mean_validation_score, the mean score over the cross-validation folds
  • cv_validation_scores, the list of scores for each fold

但是,您将不会获得两个指标.这种优化器的全部目的是最大化某些单一的度量/得分函数,因此仅此东西存储在对象内部.为了获得这种效果,您将需要运行两次,每次使用不同的计分功能.

However you will not get two metrics. The whole point of such optimizers is to maximize some single metric/scorer function, thus only this thing is stored inside of an object. In order to get such, you will need to run it twice, each time with different score function.

这篇关于如何从GridSearchCV的每一折中获得准确性和f1分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆