0

Can anyone please help me with my code?

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)) print(type(confusion_matrix(y_pred, y_true))) #in addition, just to be sure. I delete this "print" when I run the code

10th Feb 2022, 5:11 PM
Olena Volkova
Olena Volkova - avatar
1 Answer
0
The points in the solution mean that the elements are doubles. 1. is the same as 1.0 Maybe there is another procedure in which you end up with a matrix of doubles and you were expected to do it that way. Anyway, if the rest of the code is correct, you can convert the elements of a matrix to double by performing some scalar operation: matrix *= 1.0
12th Feb 2022, 9:45 AM
David
David - avatar