Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 混淆矩阵“;Can';t处理多类和未知的混合”;_Python_Numpy_Scikit Learn_Multilabel Classification - Fatal编程技术网

Python 混淆矩阵“;Can';t处理多类和未知的混合”;

Python 混淆矩阵“;Can';t处理多类和未知的混合”;,python,numpy,scikit-learn,multilabel-classification,Python,Numpy,Scikit Learn,Multilabel Classification,我的混淆矩阵显示了一个我无法理解的错误。 我想要一个混淆矩阵来显示两个数组之间的混淆,y\u pred和y\u test import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import confusion_matrix, roc_curve, auc from sklearn.metrics import accuracy_score import pylab as pl # Code that fi

我的混淆矩阵显示了一个我无法理解的错误。 我想要一个混淆矩阵来显示两个数组之间的混淆,
y\u pred
y\u test

import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix, roc_curve, auc
from sklearn.metrics import accuracy_score
import pylab as pl

# Code that fills up two numpy arrays, y_test and y_pred with integers

print y_test.shape
print y_pred.shape

cm = confusion_matrix(y_test,y_pred)
plt.matshow(cm)
plt.title('Confusion matrix')
plt.colorbar()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
错误是:

Traceback (most recent call last):
  File "C:\work_asaaki\code\test_samme_46_classes_unconfused.py", line 159, in <module>
    cm = confusion_matrix(y_test,y_pred)
  File "C:\Anaconda\lib\site-packages\sklearn\metrics\metrics.py", line 742, in confusion_matrix
    y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred)
  File "C:\Anaconda\lib\site-packages\sklearn\metrics\metrics.py", line 115, in _check_clf_targets
    "".format(type_true, type_pred))
ValueError: Can't handle mix of multiclass and unknown
回溯(最近一次呼叫最后一次):
文件“C:\work\u asaaki\code\test\u samme\u 46\u classes\u unconfliced.py”,第159行,在
cm=混淆矩阵(y_测试,y_预测)
文件“C:\Anaconda\lib\site packages\sklearn\metrics\metrics.py”,第742行,在混乱矩阵中
y_type,y_true,y_pred=_check_clf_targets(y_true,y_pred)
文件“C:\Anaconda\lib\site packages\sklearn\metrics\metrics.py”,第115行,位于检查目标中
“”.format(type_true,type_pred))
ValueError:无法处理多类和未知的混合
这个错误意味着什么?
当我打印出
y_pred.shape
y_test.shape
时,我得到了相同的形状(318L)。两个数组的值都在0到29之间。

没关系,我找到了答案,答案很简单。 问题是在代码(未显示)中,我使用
dtype=object
将y_pred填充为numpy数组,如下所示:

y_pred = np.array(pickle.load(file("PATH_TO_FILE")), dtype=object)
我删除了
dtype=object
部分,它工作正常