ValueError:"balanced_accuracy"在scikit-learn中不是有效的评分值 [英] ValueError: 'balanced_accuracy' is not a valid scoring value in scikit-learn
问题描述
我尝试将balanced_accuracy
的其他评分指标传递给GridSearchCV
进行二进制分类(而不是默认的accuracy
)
I tried to pass to GridSearchCV
other scoring metrics like balanced_accuracy
for Binary Classification (instead of the default accuracy
)
scoring = ['balanced_accuracy','recall','roc_auc','f1','precision']
validator = GridSearchCV(estimator=clf, param_grid=param_grid, scoring=scoring, refit=refit_scorer, cv=cv)
并收到此错误
ValueError:"balanced_accuracy"不是有效的评分值.有效的 选项是 ['accuracy','adjusted_mutual_info_score','adjusted_rand_score','average_precision','completeness_score','explained_variance','f1','f1_macro','f1_micro','f1_samples','f1_coreed',' homogeneity_score','mutual_info_score','neg_log_loss','neg_mean_absolute_error','neg_mean_squared_error','neg_mean_squared_log_error','neg_median_absolute_error','normalized_mutual_ision_ision'prec''pre' ,'r2','recall','recall_macro','recall_micro','recall_samples','recall_weighted','roc_auc','v_measure_score']
ValueError: 'balanced_accuracy' is not a valid scoring value. Valid options are ['accuracy','adjusted_mutual_info_score','adjusted_rand_score','average_precision','completeness_score','explained_variance','f1','f1_macro','f1_micro','f1_samples','f1_weighted','fowlkes_mallows_score','homogeneity_score','mutual_info_score','neg_log_loss','neg_mean_absolute_error','neg_mean_squared_error','neg_mean_squared_log_error','neg_median_absolute_error','normalized_mutual_info_score','precision','precision_macro','precision_micro','precision_samples','precision_weighted','r2','recall','recall_macro','recall_micro','recall_samples','recall_weighted','roc_auc','v_measure_score']
这很奇怪,因为应使用'balanced_accuracy'有效
如果不定义balanced_accuracy
,则代码可以正常工作
This is strange because 'balanced_accuracy' should be valid
Without defining balanced_accuracy
then the code works fine
scoring = ['recall','roc_auc','f1','precision']
Also the scoring metrics in the error above seems to be different from the ones in the document
任何想法为何?非常感谢
Any ideas why? Thank you so much
scikit-learn
版本为0.19.2
scikit-learn
version is 0.19.2
推荐答案
如果要使用balanced_accuracy
,请将sklearn更新到最新版本.从 0.19文档中可以看到balanced_accuracy
不是有效的评分指标.在中添加了0.20 .
Update your sklearn to the latest version if you want to use balanced_accuracy
. As you can see from the 0.19 documentation balanced_accuracy
is not a valid scoring metric. It was added in 0.20.
这篇关于ValueError:"balanced_accuracy"在scikit-learn中不是有效的评分值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!