如何将点添加到 numpy.ndarray 输出中?
How can I add the dots into numpy.ndarray output?
给定两个长度相同的1s和0s列表(1代表true标签,0代表false标签),输出2darray of counts,每个cell定义如下
左上角:预测为真且实际为真(真阳性)
右上角:预测为真但实际上为假(误报)
左下:预测为假但实际上为真(假阴性)
右下:预测为假,实际为假(真阴性)
示例输入
1 1 0 0
1 0 0 0
示例输出
[[1., 0.],
[1., 2.]]
我的代码输出:
[[1 0]
[1 2]]
我在哪里可以得到这些点???不关心逗号,我不知道为什么,但没有它们的答案是正确的。
我的代码:
import numpy as np
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
y_true = np.array(list(map(lambda x: 0 if x == 1 else 1, y_true)))
y_pred = np.array(list(map(lambda x: 0 if x == 1 else 1, y_pred)))
from sklearn.metrics import confusion_matrix
print(confusion_matrix(y_pred, y_true))
有圆点是因为这些数字是浮点数。您需要添加 .astype(float)
:
print(confusion_matrix(y_pred, y_true).astype(float))
给定两个长度相同的1s和0s列表(1代表true标签,0代表false标签),输出2darray of counts,每个cell定义如下
左上角:预测为真且实际为真(真阳性) 右上角:预测为真但实际上为假(误报) 左下:预测为假但实际上为真(假阴性) 右下:预测为假,实际为假(真阴性)
示例输入
1 1 0 0
1 0 0 0
示例输出
[[1., 0.],
[1., 2.]]
我的代码输出:
[[1 0]
[1 2]]
我在哪里可以得到这些点???不关心逗号,我不知道为什么,但没有它们的答案是正确的。
我的代码:
import numpy as np
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
y_true = np.array(list(map(lambda x: 0 if x == 1 else 1, y_true)))
y_pred = np.array(list(map(lambda x: 0 if x == 1 else 1, y_pred)))
from sklearn.metrics import confusion_matrix
print(confusion_matrix(y_pred, y_true))
有圆点是因为这些数字是浮点数。您需要添加 .astype(float)
:
print(confusion_matrix(y_pred, y_true).astype(float))