title: How to write a confusion matrix
body: <p>I wrote a confusion matrix calculation code in Python:</p>
  <pre><code>def conf_mat(prob_arr, input_arr):
      # confusion matrix
      conf_arr = [[0, 0], [0, 0]]
  
      for i in range(len(prob_arr)):
          if int(input_arr[i]) == 1:
              if float(prob_arr[i]) &lt; 0.5:
                  conf_arr[0][1] = conf_arr[0][1] + 1
              else:
                  conf_arr[0][0] = conf_arr[0][0] + 1
          elif int(input_arr[i]) == 2:
              if float(prob_arr[i]) &gt;= 0.5:
                  conf_arr[1][0] = conf_arr[1][0] +1
              else:
                  conf_arr[1][1] = conf_arr[1][1] +1
  
      accuracy = float(conf_arr[0][0] + conf_arr[1][1])/(len(input_arr))
  </code></pre>
  <p><code>prob_arr</code> is an array that my classification code returned and a sample array is like this:</p>
  <pre><code> [1.0, 1.0, 1.0, 0.41592955657342651, 1.0, 0.0053405015805891975, 4.5321494433440449e-299, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.70943426182688163, 1.0, 1.0, 1.0, 1.0]
  </code></pre>
  <p><code>input_arr</code> is the original class labels for a dataset and it is like this:</p>
  <pre><code>[2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 1]
  </code></pre>
  <p>What my code is trying to do is: I get <code>prob_arr</code> and <code>input_arr</code> and for each class (1 and 2) I check if they are misclassified or not.</p>
  <p>But my code only works for two classes. If I run this code for a multiple classed data, it doesn't work. How can I make this for multiple classes?</p>
  <p>For example, for a data set with three classes, it should return: <code>[[21, 7, 3], [3, 38, 6],[5, 4, 19]]</code>.</p>