Anyone solved this | Sololearn: Learn to code for FREE!

0

Anyone solved this

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)

5/5/2021 9:09:13 PM

Nikola Trajkoski

4 Answers

New Answer

+1

y_true = [int(x) for x in input().split()] y_pred = [int(x) for x in input().split()] from sklearn.metrics import confusion_matrix import numpy as np cm = confusion_matrix(y_pred, y_true, labels=[1,0]) print(np.array(cm, dtype='f'))

0

Do you need advice how to approach this? You could loop over the elements of the lists (index from 0 to list length), classify them (like 00, 01, 10, 11) and increment the respective cell in the 2darray by one. Or for each of the four cells in the 2darray you could count how many rows from the lists match the defined condition for the cell

0

Thanks, I solved it

0

y_true = [int(x) for x in input().split()] y_pred = [int(x) for x in input().split()] from sklearn.metrics import confusion_matrix import numpy as np matrix = confusion_matrix(y_pred, y_true, labels=[1,0]) print(np.array(matrix, dtype='f'))