简体   繁体   English

如何从 GridSearchCV 中的每个折叠中获得准确度和 f1 分数?

[英]How to get accuracy and f1-score from each fold in GridSearchCV?

I'm using the GridSearchCV object to train a classifier.我正在使用 GridSearchCV 对象来训练分类器。 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.我设置了 5 折验证参数搜索,在调用 fit() 之后,我需要查看每个折验证集的指标,即准确度和 f1 分数。 How can I do this?我怎样才能做到这一点?

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

Note:笔记:

  • I don't have a separate testing set to use so I can't just take the result of predict and do it with the standard metrics functions.我没有单独的测试集可以使用,所以我不能只获取 predict 的结果并使用标准度量函数来执行它。
  • using the clf.best_scores_ doesn't give the information I want, only the mean_validation_score and its standard deviation.使用 clf.best_scores_ 没有提供我想要的信息,只有 mean_validation_score 及其标准偏差。

Scores are located in grid_scores_ , in particular in cv_validation_scores :分数位于grid_scores_ ,特别是在cv_validation_scores

grid_scores_ : list of named tuples grid_scores_ : 命名元组列表

Contains scores for all parameter combinations in param_grid.包含 param_grid 中所有参数组合的分数。 Each entry corresponds to one parameter setting.每个条目对应一个参数设置。 Each named tuple has the attributes:每个命名元组都具有以下属性:

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

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.为了得到这样的结果,你需要运行它两次,每次使用不同的分数函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 scikit-learn 的分类问题中为 F1 分数做 GridSearchCV? - How to do GridSearchCV for F1-score in classification problem with scikit-learn? 从scikit-learn列表GridSearchCV中每个折叠的准确性和均值 - Tabulate accuracy and mean for each fold in GridSearchCV from scikit-learn 打印包含每个查询的准确率、精确度、召回率和 F1 分数的字典 - Print dictionary containing accuracy, precision, recall and F1-score for each query 如何在 python 中计算一类 SVM 的准确度、F1 分数、召回率、精度和 EER? - How to compute accuracy, F1-score, recall, precision and EER for one-class SVM in python? 如何使用 scikit learn 计算多类案例的准确率、召回率、准确率和 f1 分数? - How to compute precision, recall, accuracy and f1-score for the multiclass case with scikit learn? 在不平衡数据集上解释 AUC、准确性和 f1 分数 - Interpreting AUC, accuracy and f1-score on the unbalanced dataset 如何提高 CNN 分类中的 F1-score - How to improve the F1-score in CNN classification 如何显示进动、召回和 F1 分数? - How to show Precession, Recall and F1-Score? 如何从Sklearn分类报告中返回精确度,召回率和F1分数的平均分数? - How to return average score for precision, recall and F1-score from Sklearn Classification report? F1分数总是〜0.75? - f1-score always ~0.75?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM