ValueError:混淆矩阵不支持multilabel-indicator [英] ValueError: multilabel-indicator is not supported for confusion matrix

查看:1569
本文介绍了ValueError:混淆矩阵不支持multilabel-indicator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的二进制分类问题中尝试使用混淆矩阵时遇到此错误. YYhat都是numpy数组.我已尝试使用.argmax作为建议的解决方案-我不再收到错误,但输出不是我所知道的混淆矩阵.

I am encountering this error when trying to use the confusion matrix in my binary classification problem. Y and Yhat are both numpy arrays. I have tried the .argmax as the proposed solution - I don't get the error anymore but the output is not the confusion matrix that I know.

Accuracy: 0.9982449999999999
Accuracy: 0.9983374013937532

shape of y =  (1, 200000)
shape of yhat =  (1, 200000)

错误

 ValueError                                Traceback (most recent call last) <ipython-input-13-ebb660b4585a> in <module>()
     12 print("shape of yhat = ", yhat.shape)
     13 
---> 14 cm = confusion_matrix(y,yhat)
     15 
     16 print("confusion matrix = ", cm)

/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight)
    250     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
    251     if y_type not in ("binary", "multiclass"):
--> 252         raise ValueError("%s is not supported" % y_type)
    253 
    254     if labels is None:

ValueError: multilabel-indicator is not supported

推荐答案

按如下所示添加代码

cm = confusion_matrix(y.argmax(axis=1),yhat.argmax(axis=1))

此处之前

这篇关于ValueError:混淆矩阵不支持multilabel-indicator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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