ValueError: 'balanced_accuracy' is not a valid scoring value in scikit-learn

删除回忆录丶 提交于 2019-12-23 19:12:04

问题


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)

and got this error

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']

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 version is 0.19.2


回答1:


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.



来源:https://stackoverflow.com/questions/53349331/valueerror-balanced-accuracy-is-not-a-valid-scoring-value-in-scikit-learn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!