【发布时间】:2021-11-21 21:27:20
【问题描述】:
我的脚本很长,但重点在这里:
result = confusion_matrix(y_test, ypred)
y_test 在哪里
>>> y_test
ZFFYZTN 3
ZDDKDTY 0
ZTYKTYKD 0
ZYNDQNDK 1
ZYZQNKQN 3
..
ZYMDDTM 3
ZYLNYFLM 0
ZTNTKDY 0
ZYYLZNKM 3
ZYZMQTZT 0
Name: BT, Length: 91, dtype: object
值是
>>> y_test.values
array([3, 0, 0, 1, 3, 0, 0, 1, 0, 3, 1, 0, 3, 1, 0, 0, 3, 0, 3, 0, 0, 0,
1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 2, 3, 3, 0, 0, 3, 3, 1, 1, 0, 2,
0, 0, 0, 3, 3, 3, 1, 0, 3, 3, 3, 2, 3, 3, 0, 1, 0, 3, 3, 0, 0, 0,
0, 0, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 3, 3, 3, 0,
0, 3, 0], dtype=object)
而ypred 是
>>> ypred
array([3, 0, 0, 1, 3, 0, 0, 1, 0, 3, 1, 0, 3, 1, 0, 0, 3, 0, 3, 0, 0, 0,
1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 2, 3, 3, 0, 0, 3, 3, 1, 1, 0, 2,
0, 0, 0, 3, 3, 3, 1, 0, 3, 3, 3, 2, 3, 3, 0, 1, 0, 3, 3, 0, 0, 0,
0, 0, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 3, 3, 3, 0,
0, 3, 0])
给予
raise ValueError("Classification metrics can't handle a mix of {0} "
ValueError: Classification metrics can't handle a mix of unknown and multiclass targets
令人困惑的是我没有看到任何个未知目标。
所以我检查了ValueError: Classification metrics can't handle a mix of unknown and binary targets,但那里的解决方案不适用于我的情况,因为所有值都是整数。
我还检查了Skitlearn MLPClassifier ValueError: Can't handle mix of multiclass and multilabel-indicator,但我的数据中没有任何编码。
如何获得混淆矩阵并避免这些错误?
【问题讨论】:
-
你试过
result = confusion_matrix(y_test.values, ypred)吗?看来您的y_test不仅仅包含类 -
我试过了,但没用
-
如果您提供更多信息会有所帮助。我的猜测是 y_test 是问题所在。它的形状是什么?有多个列,这就是错误显示多类目标的原因