如何修复ValueError:不支持多类格式 [英] How to fix ValueError: multiclass format is not supported

查看:14
本文介绍了如何修复ValueError:不支持多类格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我试图计算ROC分数,但我遇到了ValueError的问题:不支持多类格式。我已经在找科学工具包学习了,但它没有帮助。最后,我仍然有ValueError:不支持多类格式。

这是我的代码

from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.metrics import confusion_matrix,zero_one_loss
from sklearn.metrics import classification_report,matthews_corrcoef,accuracy_score
from sklearn.metrics import roc_auc_score, auc


dtc = DecisionTreeClassifier()
bc = BaggingClassifier(base_estimator=dtc, n_estimators=10, random_state=17)
bc.fit(train_x, train_Y)
pred_y = bc.predict(test_x)

fprate, tprate, thresholds = roc_curve(test_Y, pred_y)
results = confusion_matrix(test_Y, pred_y)
error = zero_one_loss(test_Y, pred_y)
roc_auc_score(test_Y, pred_y)

FP = results.sum(axis=0) - np.diag(results)  
FN = results.sum(axis=1) - np.diag(results)
TP = np.diag(results)
TN = results.sum() - (FP + FN + TP)



print('
 Time Processing: 
',time.process_time())
print('
 Confussion Matrix: 
', results)
print('
 Zero-one classification loss: 
', error)
print('
 True Positive: 
', TP)
print('
 True Negative: 
', TN)
print('
 False Positive: 
', FP)
print('
 False Negative: 
', FN)
print ('
 The Classification report:
',classification_report(test_Y,pred_y, digits=6))
print ('MCC:', matthews_corrcoef(test_Y,pred_y))
print ('Accuracy:', accuracy_score(test_Y,pred_y))
print (auc(fprate, tprate))
print ('ROC Score:', roc_auc_score(test_Y,pred_y))

这是回溯

推荐答案

来自文档的roc_curve:"注意:此实现仅限于二进制分类任务。"

您的标签分类(Y)是1还是0?如果不是,我认为您必须将pos_label参数添加到roc_curve调用中。

fprate, tprate, thresholds = roc_curve(test_Y, pred_y, pos_label='your_label')

或:

test_Y = your_test_y_array  # these are either 1's or 0's
fprate, tprate, thresholds = roc_curve(test_Y, pred_y)

这篇关于如何修复ValueError:不支持多类格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆