[英]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:笔记:
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.