Confusion matrix in sklearn If you look at this:
&gt;&gt;&gt; y_true = [&quot;cat&quot;, &quot;ant&quot;, &quot;cat&quot;, &quot;cat&quot;, &quot;ant&quot;, &quot;bird&quot;]
&gt;&gt;&gt; y_pred = [&quot;ant&quot;, &quot;ant&quot;, &quot;cat&quot;, &quot;cat&quot;, &quot;ant&quot;, &quot;cat&quot;]
&gt;&gt;&gt; confusion_matrix(y_true, y_pred, labels=[&quot;ant&quot;, &quot;bird&quot;, &quot;cat&quot;])
array([[2, 0, 0],
       [0, 0, 1],
       [1, 0, 2]])

I suppose fist row of array means &quot;predicted ant&quot; and first column is &quot;actually is ant&quot; second column is &quot;actually is bird&quot; etc.
So first row first col 2 i read like &quot;predicted ant, is ant&quot;, first row second col 0 i read as &quot;precited ant is bird&quot; is 0 which fits, and third column is &quot;predicted ant is cat&quot; is 0 but should be 1.
What i am doing wrong while understanding the confusion matrix.
Another example is this
&gt;&gt;&gt; from sklearn.metrics import confusion_matrix
&gt;&gt;&gt; y_true = [2, 0, 2, 2, 0, 1]
&gt;&gt;&gt; y_pred = [0, 0, 2, 2, 0, 2]
&gt;&gt;&gt; confusion_matrix(y_true, y_pred)
array([[2, 0, 0],
       [0, 0, 1],
       [1, 0, 2]])

Where is not even clear, what is the order of classes.
Source: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
edit: Unless it is swapped. First row is &quot;is ant&quot; not &quot;predicted ant&quot;. Only that on wikipedia the system is that row is the prediction.
You just confused the actual and predicted. Every row represents actual values of distinct elements in your array and columns represent predicted values of them. That is,


First row: There are 2 ants, and 2 samples are predicted as ant.
Seconds row: There are 1 bird and 1 sample is predicted as cat.
Third row: There are 3 cats, 1 sample is predicted as ant, 2 samples are predicted as cat.