0
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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.

enter image description here

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} $$

$\endgroup$
-1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ No. I have a classifier which has a 2 classes. Now I have to calcualte precision and recall. and I don't know how? $\endgroup$ – sara Nov 23 '16 at 18:16
  • $\begingroup$ 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. $\endgroup$ – mp85 Nov 23 '16 at 18:23
  • $\begingroup$ 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? $\endgroup$ – sara Nov 23 '16 at 18:28
  • $\begingroup$ No, just one confusion matrix. There is all the information you need to compute each statistics for the two classes. $\endgroup$ – mp85 Nov 23 '16 at 18:43
  • $\begingroup$ would you please have a look at the link below: $\endgroup$ – sara Nov 23 '16 at 20:58

Your Answer

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.