# confusion matrix for 2 classes

I have a file containing some sentences. Each sentence belongs to a specific class. There are 2 classes,

• "passion"
• "salty".

I classified them with Naive bayes algorithm and now I have to calculate precision and recall.
My question now is, if I want to make confusion matrix, should I first make one for "passion" group and then one for "salty" group (have 2 confusion matrices)?
If so, then how should I calculate precision and recall from these 2 matrices?

My question now is, if I want to make confusion matrix, should I first make one for "passion" group and then one for "salty" group (have 2 confusion matrices)?

You misunderstand what a confusion matrix is.

A confusion matrix for a problem with a number of C classes is a C x C square matrix. Usually the horizontal margin represents the true classes, while the vertical margin represents the predicted classes, however this is sometimes exchanged. Into this we fill in the number of instances that our classifier correctly predicted as class A (top left), wrongly predicted as class A (top right), wrongly predicted as class B (bottom left) and correctly predicted as class B (bottom right). This easily extends to problems with more than 2 classes, containing one correct prediction per row but more incorrect ones.

In your case, A and B can be replaced with 'passion' and 'salty'. The calculation of recall and precision is fairly straightforward then.

$$\mathrm{Precision}(A) = \frac{\#True A}{\#True A + \#False A}$$ $$\mathrm{Recall}(A) = \frac{\#True A}{\#True A + \#False B}$$

You mean passion can take values (yes/no) and salty can take values (yes/no)? if that's the case, you have four classes, not two. That would result in a 4x4 confusion matrix.

Otherwise, I cannot understand your request.

(I would have commented this post, but I don't have enough reputation, hence I'm posting a full response, you can comment this post if you feel like providing more information).

• No. I have a classifier which has a 2 classes. Now I have to calcualte precision and recall. and I don't know how? – sara Nov 23 '16 at 18:16
• Then you are already set to use a confusion matrix, since the classes are two. Call salty the "P" and passion the "N", and see how wikipedia constructs a confusion matrix for two classes. – mp85 Nov 23 '16 at 18:23
• I read them all before. My question is: should make just 1 matrix or 2 (for each class separately), and then have an average of them? – sara Nov 23 '16 at 18:28
• No, just one confusion matrix. There is all the information you need to compute each statistics for the two classes. – mp85 Nov 23 '16 at 18:43
• would you please have a look at the link below: – sara Nov 23 '16 at 20:58