im trying to do a research but i need to make a confusion matrix how can i do that on this model?
https://www.kaggle.com/code/stpeteishii/race-classify-densenet201
Sorry im so so new to everything.
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.
Sign up to join this communityim trying to do a research but i need to make a confusion matrix how can i do that on this model?
https://www.kaggle.com/code/stpeteishii/race-classify-densenet201
Sorry im so so new to everything.
Without having read too much your code, a confusion matrix states how many elements from class $y_1, y_2, y_3..$ have been associated by the model to class $y_1, y_2, y_3..$
So, for n classes, the matrix size is nxn.
Each row of the matrix should represent $y_i$, while each column should represent $y'_i$, so each row should represent the actual class, while each column the predicted class.
This image took from Wikipedia represents a confusion matrix. I don't know why, but some cells are left empty. Maybe empty means 0.
As you see, the main diagonal numbers represent the number of true predictions for each class $y_i$.
To implement a confusion matrix with a library, here's the following code that may help you:
from sklearn.metrics import confusion_matrix
y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]
y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]
confusion_matrix(y_actu, y_pred)
Output in this case is a 3x3 array:
array([[3, 0, 0],
[0, 1, 2],
[2, 1, 3]])
Confusion matrices are supported by scikit-learn (see also lya Lees answer). In cell 1, you can import it via
from sklearn.metrics import classification_report, log_loss, accuracy_score, confusion_matrix
Then in Cell [19] (or in a later cell), you can call it similar to classification_report
:
print(confusion_matrix(ground,pred))