0
$\begingroup$

I'm not understanding how to calculate Precision and Recall if I'm doing image classification.

If I have two classes, Cat and Dog, and for evaluation I get an image of a Dog and the model classifies it as a Cat, then is it a False Positive or False Negative?

$\endgroup$

3 Answers 3

1
$\begingroup$

The blow image describes what it means, replace

Positive -> cat;

Negative -> Dog;

Then

If a dog is predicted as cat -> FP

If Cat is predicted as Dog -> FN;

So, both of them are showing errors in model behavior; one shows error related to cat class and the other is in Dog class (depends on how you define error)

Read more on this blog enter image description here

$\endgroup$
2
  • $\begingroup$ Then the precision and recall values are gonna keep on changing depending on what I choose to be as positive and negative $\endgroup$
    – Anubhav Guha
    Commented Apr 6, 2022 at 8:00
  • 1
    $\begingroup$ The values will be reversed only. Its up to you do define positive or negative class. $\endgroup$ Commented Apr 6, 2022 at 8:53
0
$\begingroup$

Your labels (e.g. Dog and Cat) are converted into numbers before modeling. Let's assume that Dog = 1 and Cat = 0, which means the positive class is 'Dog' and the negative is 'Cat'. Which leads to:

If prediction is 0 and true label is 1, then it's a false negative.

If prediction is 1 and true label is 0, then it's a false positive.

The way you define positive/negative class is up to you.

$\endgroup$
0
$\begingroup$

First, you should know the concepts of True Positive(TP), False Negative(FN), False Positive(FP) and True Negative(TN).

These four items form the confusion matrix.

You can define a Positive class as you want, e.g. you can choose Dog as postive class(often, we choose the class we care most as the positive class, like cancer vs. non-cancer case, we set cancer as positive class).

Then if the image is with a dog(we call it groudtruth), you predict it as a dog, you get TP; if the image is with a cat, you predict it as a cat, you get TN; if the image is with a dog, you predict it as a cat, you get FN; if the image is with a cat, you predict it as a dog, you get FP.

Now you can count the number of TP, TN, FN, FP as #TP, #TN, #FN, #FP. So the Precison is defined as: TP / (TP + FP); Recall is defined as: TP / (TP + FN)

You can see from the above fomula, Preciosn means how many predictions you made are right of all you predictions while Recall means how many actual positive classes you predictions have coverd.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.