Given two lists of 1s and 0s (1 represents the true label, and 0 represents the false false) of the same length, output a 2darrary of counts, each cell is defined as follows
Top left: Predicted true and actually true (True positive) Top right: Predicted true but actually false (False positive) Bottom left: Predicted false but actually true (False negative) Bottom right: Predicted false and actually false (True negative)
Sample Input
1 1 0 0
1 0 0 0
Sample Output
[[1., 0.],
[1., 2.]]
My code outputs:
[[1 0]
[1 2]]
Where can I get those dots??? Don't care about commas, i don't know why, but the answer without them is correct.
My code:
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))
CodePudding user response:
The dots there are because those numbers are floating points. You'll need to add .astype(float)
:
print(confusion_matrix(y_pred, y_true).astype(float))