【发布时间】:2021-06-25 07:44:59
【问题描述】:
之前肯定有人问过,但我没有成功分析其他帖子针对我自己的这个问题实例的解决方案。
我有很多分类模型要使用confusion_matrix()进行比较
matrix = confusion_matrix(y_test, y_pred) # ERROR
>>> y_pred
[[2 2 2 ... 2 2 2]
[2 2 2 ... 2 2 2]
[2 2 2 ... 2 2 2]
...
[3 3 2 ... 3 2 3]
[2 2 2 ... 2 2 2]
[3 3 3 ... 3 3 3]]
>>> y_pred.shape
(500, 256)
>>> y_test
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
>>> y_test.shape
(500, )
错误:
ValueError: Classification metrics can't handle a mix of multiclass and multiclass-multioutput targets
当.flatten() 对y_pred 执行时 - 即一维数组 (500 * 256 = 128000):
ValueError: Found input variables with inconsistent numbers of samples: [500, 128000]
【问题讨论】:
-
y_pred 应该是一维数组以进行比较
-
你的 y_pred 是如何进入二维数组的?你在 y 做了哪些预处理?
-
所以我将 'y_pred = model.predict(X_test_seq)' 转换为与 'X_test_seq' 相同的形状
-
y_pred扁平化后的形状是什么? -
你能告诉我预测的
[2,2,2,2....2]是什么意思吗?你的 y 是多少?
标签: python neural-network classification confusion-matrix multilabel-classification