解决sklearn.metrics指标报错ValueError: Target is multiclass but average=‘binary‘. Please choose anothe...

完整报错为:ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].

解决方法

对于多分类任务,将

from sklearn.metrics import f1_score
f1_score(y_test, y_pred)

改为:

f1_score(y_test, y_pred,average='macro') # average按任务需要计算

可以参考:https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html

你可能感兴趣的:(数据处理,sklearn)