[英]Confusion Matrix ValueError: Classification metrics can't handle a mix of binary and continuous targets
[英]ValueError: Classification metrics can't handle a mix of binary and continuous targets
y_test.shape
output: (40,)
predict.shape
output: (40,1)
confusion_matrix(y_test, predict)
錯誤:ValueError:分類指標無法處理二進制和連續目標的混合
我在 CNN model 對文本數據的預測中應用混淆矩陣,但收到一條錯誤消息,即混淆矩陣無法處理二進制和連續數據的混合
當分類器產生准概率估計時,例如在神經網絡中使用交叉熵損失時,有時會發生這種情況。
import numpy as np
y_test = np.array([0, 1, 0])
y_pred = np.array([[0.1], [0.7], [0.2]])
print(y_test.shape, y_pred.shape)
# (3,) (3, 1)
這是通過對預測設置閾值來解決的。 0.5 是一個常見的選擇:
from sklearn.metrics import confusion_matrix
confusion_matrix(
y_test,
(y_pred > 0.5),
)
# array([[2, 0],
# [0, 1]])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.