The best way to understand Precision and Recall : As clear as crystal

Karim cossentini
6 min readOct 22, 2020

One of the most common questions when interviewing for a data science position is the metric that you would be using in a classification task. Therefore, you may find yourself in a position in which you have to use the terms “Precision” and “Recall”.This article provides you with a thourough and clear explanation of these two concepts in order to be able to distinguish between two basic data science metrics which seem a bit confusing at the first glance, and of course, to get your dream job !

Before starting, here are some insights about these two metrics as a quick reminder:

Precision: is the fraction of relevant instances among the retrieved instances

Recall : is the fraction of the total amount of relevant instances that were actually retrieved.

Let us suppose that our task was to classify items in two classes : “Defective item” and “None defective item”

Positive class (1): Defective item

Negative class (0): None Defective item

True Positives (TP) :Items belonging to the positive class and correctly classified as such.

False Positives (FP) : Items belonging to the negative class and incorrectly classified as positive.

True Negatives (TN) : Items belonging to the negative class and correctly classified as such.

False Negatives (FN) : Items belonging to the positive class and incorrectly classified as negative .

Now that we are clear with these concepts let us move to the next part of this blog

One of the most popular mistakes that data scientists make when asked about the meaning of Precision and Recall is to repeat their definitions which as you can see is not the perfect way to introduce yourself as for making a good impression, on the other hand it is only going to ding you in an endless cycle of explaining and the recruter will get bored because this is a hard concept to grasp in the beginning. Instead you should Think of a fitting example for your response and Then try to share the details in a compelling and easy-to-understand way without endless rambling.

So, I am going to explain these two terms for you based on a real life practical example, which is the way I believe a data scientist should see things.

During the pandemic, David feeling bored in his confinement, wants to buy a guitar Let’s call it (Item D) to have some fun and enjoy his time, So he opens his phone and trys to search for this item in an online store and that’s what he gets:

⇩⇩

What are the chances that the store’s search engine will be able to recall ‘’Item D’’ precisely?

If you understood my previous question, then you may already have understood what recall and Precision actually mean. However, for more confirmation, this is my analysis.

⇩⇩

I should mention here that :

Positive class (1) refers to : the requested item that david wants to buy (In Green)

Negative class (0) refers to : Not the requested item that david wants to buy (In Red)

As we see in the search results, we notice that the search system gives us the specific item that David wants to buy (item D) and thus we can say that our Recall is 100% (TP=1; FN = 0)

On the other hand , the system gave us a lot of unrequested items (in Red), So it’s obvious that the system is not precise enough because it shows us many irrelevant results, which is why our Precision is 1/6 = 16% .

Let me explain this a little more :

The system predicts the True item which is ‘Item D’(True: 1 🢂 Predited: 1) so TP=1, but it also predicts that items (in Red) are the True ones that david wants to buy (True:0 🢂 Predited:1) which is not the case , that’s why FP=5

Second Case:

Now David wants to buy two Items (Item D) and (Item K):

We notice that the search system gave us one requested item of two ,which is only (itemD) but the (item k) is unfound and thus ,our Recall is 50%

In other words, the system predicts a True item (Item D) (True:1 🢂 Predited:1)so TP=1,but it predicts that the second requested item (Item k) is not desirable by the customer (True:1 🢂 Predited:0) which is not the case and that’s why it didn’t show up in the search results , so FN=1.

The Precision stays the same as before which is 1/6 = 16%.

Final Case:

David wants to buy two items D and K and the system gave us only the (Item D) .

Now the Recall stands by 50% because the system didn’t recall all the requested items while the Precision is certainly 100% (there is no False items in the search results)

As a conclusion we can say that Precision is a measure of result relevancy, while Recall is a measure of how many truly relevant results are returned

How to achieve 100% of Precision and Recall ?

David wants to buy (item D) from online store 🢂 The search system outputs item D regardless of any other item that has been shown 🢂 We achieve 100% Recall

David wants to buy item D 🢂 The system outputs only (item D) (nothing else) 🢂 We achieve 100% Precision

To simplify more:

All positive labels (1) classified correctly 🢂 100% Recall

All negative labels (0) classified correctly + one positive label (1) classified correctly is enough🢂 100% Precision

Why both Precision and Recall are so important ?

Imagine that every time you search for a product in an online store, you notice that the Precision is very low so you start to get irrelevant results and finally you will switch to another platform or even give up the idea of ​​buying which is why Precision and Recall are so important. In other words, if the system must recall everything (to achieve a high Recall rate), it will have to keep generating inaccurate results, thereby reducing Precision and by this time, you might have guessed that one comes at the cost of the other.

Congratulations on making it to the end of the article! I hope this explanation is engaging and helpful to those starting out on Data Science and working on Classification problems.

Feel free to comment on the post or connect with me on LinkedIn.I look forward to your feedback and suggestions.

--

--

Karim cossentini

I am an ICT student at SUP’COM with a particular interest in Computer Vision and Artificial Intelligence