1
$\begingroup$

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.

New contributor
Ayberk İlbak is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
2
  • $\begingroup$ Can you please explain what the link has to do with your question? It would also be helpful to know whether you try to understand the concept of confusion matrices or whether you are looking for a concrete implementation. $\endgroup$
    – Broele
    2 days ago
  • $\begingroup$ im looking for concrete implementation. The link is for i want to add that model to a confusion matrix but i couldnt manage to figure it out sadly $\endgroup$ 2 days ago

2 Answers 2

0
$\begingroup$

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.

enter image description here

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]])

source

New contributor
Iya Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
2
  • $\begingroup$ Thank you i will check it but is there anything that i could peek up like directories to implement an confusion matrix $\endgroup$ Mar 14 at 21:13
  • $\begingroup$ Answer updated, I think that's acceptable now $\endgroup$
    – Iya Lee
    Mar 14 at 21:16
0
$\begingroup$

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))
$\endgroup$

Your Answer

Ayberk İlbak is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.