I have a csv file with true and predicted labels (4 classes) associated with an ID. The csv file looks like this:
task_id,labels_true,labels_pred
76017-126511-18,2,2
76017-126512-18,0,3
76017-126513-18,2,2
76018-126511-18,2,2
76018-126512-18,2,2
76018-126513-18,2,1
76019-126511-18,2,2
76019-126512-18,1,0
I am using the confusion matrix from sklearn.metrics
y_true = df["labels_true"]
y_pred = df["labels_pred"]
cnf_matrix = confusion_matrix(y_true, y_pred, labels=[0,1,2,3])
It returns an array as follows:
[[ 554 1 28 0]
[ 15 1375 43 0]
[ 42 476 2263 0]
[ 0 0 0 0]]
My aim is to return a list with each element ID associated with the respective tp, tn, fp, fn values like this:
task_id,labels_true,labels_pred, cm
76017-126511-18,2,2, tp
76017-126513-18,2,2, tp
76018-126511-18,2,2, tp