面临 ValueError:目标是多类但平均 = 二进制

我是 Python 和机器学习的新手。根据我的要求,我正在尝试对我的数据集使用朴素贝叶斯算法。


我能够找出准确度,但试图找出相同的精确度和召回率。但是,它抛出以下错误:


   "choose another average setting." % y_type)

ValueError: Target is multiclass but average='binary'. Please choose another average setting.

任何人都可以建议我如何进行。我尝试在精度和召回分数中使用平均 ='micro'。它没有任何错误,但它在准确性、精确度和召回方面给出了相同的分数。


我的数据集:

train_data.csv:

review,label

Colors & clarity is superb,positive

Sadly the picture is not nearly as clear or bright as my 40 inch Samsung,negative

测试数据.csv:

review,label

The picture is clear and beautiful,positive

Picture is not clear,negative


慕标琳琳
浏览 482回答 1
1回答

撒科打诨

您需要添加'average'参数。根据文档:平均值:字符串,[无,'二进制'(默认),'微','宏','样本','加权']多类/多标签目标需要此参数。如果None,则返回每个班级的分数。否则,这将确定对数据执行的平均类型:做这个:print("Precision Score : ",precision_score(y_test, y_pred,                                            pos_label='positive'                                           average='micro'))print("Recall Score : ",recall_score(y_test, y_pred,                                            pos_label='positive'                                           average='micro'))替换'micro'为上述任何一个选项,除了'binary'. 此外,在多类设置中,无需提供 ,'pos_label'因为它无论如何都会被忽略。更新评论:是的,它们可以相等。它在用户指南中给出:请注意,对于包含所有标签的多类设置中的“微”平均将产生相同的精度、召回率和 F,而“加权”平均可能会产生不在精度和召回率之间的 F 分数。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python