2017-08-07 49 views
0

我正在使用confusion_matrix模块来将类别预测结果与实际值进行比较。Scikit-learn ValueError:使用混淆矩阵时不支持未知

val= ... #shape (3000,1,30) dtype float32 
pred = ... #shape (3000,1,30) dtype float32 

cnf_matrix = confusion_matrix(val, pred) #ERROR HERE 

我得到这个错误:

Traceback (most recent call last): File "vis.py", line 757, in cnf_matrix = confusion_matrix(y_test, y_pred) File "C:\Anaconda\envs\nn35\lib\site-packages\sklearn\metrics\classification.py", line 240, in confusion_matrix y_type, y_true, y_pred = _check_targets(y_true, y_pred) File "C:\Anaconda\envs\nn35\lib\site-packages\sklearn\metrics\classification.py", line 89, in _check_targets raise ValueError("{0} is not supported".format(y_type)) ValueError: unknown is not supported

我做了什么错?

回答

0

问题是真实值的形状,预测必须是(3000,30)而不是(3000,1,30)。所以我重塑它使用pred= np.reshape(pred, (pred.shape[0], 30))