在用CNN网络做故障诊断时想要获取混淆矩阵,但是系统却报错了,原代码长这样
from sklearn.metrics import confusion_matrix
y_pred = model(x).detach()
y_true = y[:, np.newaxis]
C = confusion_matrix(y, y_pred)
显示Classification metrics can't handle a mix of continuous and multiclass targets
于是看了一下y_true, y_pred的数据,发现经过CNN预测得到的y_pred不是整数,而y_true是整数

所以把代码改为
y_pred = model(x).detach()
_, indexes = y_pred.max(1)
y_true = y[:, np.newaxis]
C = confusion_matrix(y_true, indexes)
indexes长这样

CNN故障诊断中混淆矩阵问题及解决方案,
1万+





