I'm using a confusion matrix that is working just fine until I get to a specific part of my numpy arrays.
The ground truth results are stored in an array called y_test
, while the classfiers' results are stored in r
.
When I use the confusion matrix for the whole set of results, there are no problems.
But I want to divide the results from my experiment.
I have 3 specific classifiers' results which are stored in arrays called c
, b
and t
.
Now I want to compare the results of these 3 specific classifiers against some specific indices of the overall results. For example, I want to highlight the confusion matrix for the results for classifier C
specifically from indices 91 to 180 of the overall results.
For classifier B
I want to see the confusion matrix of the results from indices 1 to 90.
And so on.
This is my code, below. For the first 2 confusion matrices, there are no problems. They show up fine.
cm_c = confusion_matrix(y_test[91:80],c[91:80])
plt.matshow(cm_c)
plt.title('Confusion matrix')
plt.colorbar()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
cm_b = confusion_matrix(y_test[1:90],b[1:90])
plt.matshow(cm_b)
plt.title('Confusion matrix')
plt.colorbar()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
cm_t = confusion_matrix(y_test[228:317,t[228:317])
plt.matshow(cm_t)
plt.title('Confusion matrix')
plt.colorbar()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
But for the last set of results above (using the results array from classifier T
), I get the following error:
cm_t = confusion_matrix(y_test[228:317], t[228:317])
IndexError: invalid index to scalar variable
I don't know what's wrong.