I wrote a confusion matrix calculation code in Python:
def conf_mat(prob_arr, input_arr):
# confusion matrix
conf_arr = [[0, 0], [0, 0]]
You should map from classes to a row in your confusion matrix.
Here the mapping is trivial:
def row_of_class(classe):
return {1: 0, 2: 1}[classe]
In your loop, compute expected_row
, correct_row
, and increment conf_arr[expected_row][correct_row]
. You'll even have less code than what you started with.