Scikit-learn ValueError:使用混淆矩阵时不支持unknown

时间:2017-08-07 16:28:11

标签: scikit-learn

我使用confusion_matrix模块可视化与实际值相比的类预测结果。

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

cnf_matrix = confusion_matrix(val, pred) #ERROR HERE

我收到了这个错误:

  

回溯(最近一次呼叫最后一次):文件" vis.py",第757行,       cnf_matrix = confusion_matrix(y_test,y_pred)文件" C:\ Anaconda \ envs \ nn35 \ lib \ site-packages \ sklearn \ metrics \ classification.py",   第240行,在confusion_matrix中       y_type,y_true,y_pred = _check_targets(y_true,y_pred)文件" C:\ Anaconda \ envs \ nn35 \ lib \ site-packages \ sklearn \ metrics \ classification.py",   第89行,在_check_targets中       引发ValueError(" {0}不受支持" .format(y_type))ValueError:不支持unknown

我做错了什么?

1 个答案:

答案 0 :(得分:0)

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

重塑它