2017-08-07 55 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))