How to write a confusion matrix in Python?

前端 未结 14 1933
太阳男子
太阳男子 2020-12-04 06:48

I wrote a confusion matrix calculation code in Python:

def conf_mat(prob_arr, input_arr):
        # confusion matrix
        conf_arr = [[0, 0], [0, 0]]

            


        
14条回答
  •  -上瘾入骨i
    2020-12-04 07:21

    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.

提交回复
热议问题