简体   繁体   English

混淆矩阵“无法处理多类和未知的混合”

[英]Confusion matrix “Can't handle mix of multiclass and unkown”

My confusion matrix is showing up an error that I can't understand. 我的混淆矩阵显示出一个我无法理解的错误。 I want a confusion matrix to show the confusion between two arrays, y_pred and y_test . 我想要一个混淆矩阵来显示两个数组y_predy_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()

The error is: 错误是:

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

What does the error mean? 错误是什么意思? When I print out y_pred.shape and y_test.shape , I get the same shape, (318L). 当我打印出y_pred.shapey_test.shape ,我得到相同的形状,(318L)。 The values of both arrays range between 0 and 29. 两个数组的值介于0到29之间。

Never mind, I found the answer, it was quite simple. 没关系,我找到了答案,这很简单。 The problem was that in the code (not shown), I had populated y_pred as a numpy array using dtype=object , liked this: 问题是在代码(未显示)中,我使用dtype=object将y_pred填充为numpy数组,喜欢这样:

y_pred = np.array(pickle.load(file("PATH_TO_FILE")), dtype=object)

I removed the dtype=object part and it worked fine. 我删除了dtype=object部分,它工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 混淆矩阵() | ValueError:分类指标无法处理多类和多类多输出目标的混合 - confusion_matrix() | ValueError: Classification metrics can't handle a mix of multiclass and multiclass-multioutput targets 混淆矩阵:ValueError:分类指标无法处理多类和连续多输出目标的混合 - Confusion matrix: ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets Keras混淆矩阵:ValueError:分类指标无法处理多类多输出和二进制目标的混合 - Keras confusion matrix: ValueError: Classification metrics can't handle a mix of multiclass-multioutput and binary targets 接收分类指标无法处理多类混淆_matrix - Receiving Classification metrics can't handle a mix of multiclass confusion_matrix 混淆矩阵错误“分类指标无法处理多标签指标和多类目标的混合” - confusion matrix error "Classification metrics can't handle a mix of multilabel-indicator and multiclass targets" ValueError:无法处理连续类和多类的混合 - ValueError: Can't handle mix of continuous and multiclass Python / Scikit-Learn - 无法处理多类和连续的混合 - Python/Scikit-Learn - Can't handle mix of multiclass and continuous Confusion_matrix ValueError:分类指标无法处理二进制和连续多输出目标的混合 - Confusion_matrix ValueError: Classification metrics can't handle a mix of binary and continuous-multioutput targets 混淆矩阵 ValueError:分类指标无法处理二进制和连续目标的混合 - Confusion Matrix ValueError: Classification metrics can't handle a mix of binary and continuous targets 如何处理 ValueError:分类指标无法处理多标签指标和多类目标错误的混合 - how to handle ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass targets error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM