How to fix ValueError: multiclass format is not supported(如何修复ValueError:不支持多类格式)
本文介绍了如何修复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:不支持多类格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何修复ValueError:不支持多类格式


基础教程推荐
猜你喜欢
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01