During the COVID-19 pandemic, over 50 crore individuals were infected. Nearly 60 lakh people lost their lives due to reasons of miscalculations. Though different nations came up with other solutions, nothing worked on a large scale.

Why? Categorizing people based on their infection status, i.e., positive and negative, was a severe problem. Therefore, getting an infected person's positive status was a difficult task. This problem can be classified as an imbalanced classification problem. Other examples of imbalanced classification problems are spam email detection and financial fraud detection, among others.

Problems like these have a different fan base in Machine Learning (ML) and Data Science domains. In such problems, accuracy is as important as the outcome, or maybe accuracy plays even a more significant role than the outcome itself. Knowing a positively infected person in that scenario is as crucial as learning about that junk email that can get your bank account emptied within a fraction of seconds.

Therefore, the precision and recall method becomes very important. In this article, we will know about it in great detail.

- 1. Key concepts to understand before understanding Precision Recall
- 1.1. False positives (FP)
- 1.2. False negatives
- 2. What is the Precision Recall method?
- 2.1. Precision
- 2.2. How to calculate precision?
- 2.3. Recall
- 2.4. How to calculate recall?
- 3. How to use Precision Recall as an ML classification method?
- 3.1. So, what is the solution to this problem?
- 3.2. What other solutions we can have?
- 4. Why use Precision Recall over other classification methods?
- 5. Difference between Precision and Recall
- 6. Use cases: Precision Recall method
- 6.1. 1. Email spam detection: (Precision focused)
- 6.2. 2. Tests for medical conditions (Recall focused)
- 6.3. 3. Criminal death penalty (Precision focused)
- 6.4. 4. Flagging fraud transactions: (Recall focused)
- 7. Precision Recall approach: Closing notes

Suppose a person receives an email stating they have won something big. The person believes that email and shares their bank account details in the following email.

What if that email turns out to be spammed or a phishing email? Can you imagine what will happen to their bank account?

So this problem is called a False Positive (FP) in the recall and precision classification method. Sometimes, it also gets notified as a Type 1 error.

Imagine the above scenario again. The person receives an email stating the same thing and asking for the bank account details. This person is smart and knows about phishing and spam emails. They simply mark it as junk and delete it.

But the story doesn’t end here as there is a catch- what if the email was for a bounty or prize money they had really won? What will happen now?

This kind of problem is known as a False Negative (FN) or Type 2 error in the classification precision and recall method.

Precision is the ratio between true positives (TP) and actual results. Thus, precision measures all the relevant data points for our Machine Learning (ML) model. In short, precision tries to solve the below problem-

What part of positive identifiers was actually correct? Or What percentage of our results were relevant?

Mathematically, precision can be defined as-

```
True Positives (TP)
```

Precision = —----------------------------------------- True Positives (TP) + False Positives (FP)

Or

```
True Positives (TP)
```

Precision = —------------------- Actual Results

(Precision Formula)

Recall is the ratio between the true positives (TP) and to that of predicted results. Recall helps us in shorting out the accuracy of our predictions by analyzing the data provided. In short, recall tries to solve the below problem-

What part of positive identifiers were identified correctly? Or What percentage of our results were classified correctly?

Mathematically, recall can be defined as-

```
True Positives (TP)
```

Recall = —----------------------------------------- True Positives (TP) + False Negative (FN)

Or

```
True Positives (TP)
```

Recall = —------------------- Predicted Results

(Recall Formula)

For better accuracy of your ML model, you should calculate and examine both the precision and recall. However, doing this is a tedious task itself because increasing the classification accuracy of your model through precision reduces the recall and the same goes the other way around.

A simple solution can be the priority of your model. Thus, based on the priority and functionality of your ML model you can decide.

Another important solution is the harmonic mean of precision and recall. This is also known as the precision recall f1 score. A precision recall f1 score formula can be derived as-

```
Precision x Recall
```

F1 score = 2 x —------------------- Precision + Recall

(f1 Score Formula)

The precision recall f1 score is a more convenient and apt method of classification, wherein you can ensure both the accuracy and inclusion of precision and recall outcomes.

The application of precision and recall depends on the issue being addressed.

When there's a need to classify all positive and negative samples as positive, regardless of whether they're classified correctly or incorrectly, then you should use precision.

On the other hand, if you aim to identify only positive samples, you should employ Recall. This is where you don't need to be concerned about whether negative samples are correctly or incorrectly classified.

Recall | Precision |
---|---|

We only need positive samples to calculate the Recall for a model. All negative samples will be ignored. | When calculating the Precision of a model, it is important that we consider both the positive and negative samples that are being classified. |

This allows us to determine how many positive samples have been correctly classified using the ML model. | This allows us to measure the ability to classify the positive samples in the model. |

Recall of the ML model is dependent upon positive samples and independent of negative samples. | Precision of the ML model depends on both the negative as well as positive samples. |

Recall cares about accurately classifying all positive samples. It doesn't care if any negative samples are classified as positive. | In Precision, all positive samples that are classified as positive should be considered either correctly or incorrectly. |

In real-life situations, there are different interpretations for each kind of error - False Positive vs False Negative. In most cases, one is more important than the other one.

Let's take a look at some of the real-life use cases of Precision Recall.

It is acceptable to miss out on a spam email being detected (low recall), but any legitimate or important email should not be sent into the spam folder (false positive).

It's okay to diagnose a healthy person with cancer (false positive) and follow up with additional medical tests. However, it is not acceptable to fail to identify a person with cancer or classify them as healthy (false negative) because the patient's life is at risk.

It is acceptable to not punish a criminal (low recall), but it is unacceptable to incriminate an innocent person (false positive).

It is acceptable to label a legitimate transaction fraudulent. It can always be reverified through additional checks. However, it is not acceptable to consider a fraudulent transaction legitimate (false positive).

Thus, the precision recall approach helps optimize our classification-based Machine Learning (ML) models. It can be more beneficial if we can achieve the balance between both precision recall.

Precision Recall: Pro tip- You won't get much from memorizing the metrics. Instead, think about which misclassifications are most dangerous and how you can prevent them. Also, keep a healthy balance between recall and precision. Machine learning models are just a means to an end. They don't represent the ultimate goal.

What are precision and recall why this is important in model evaluation?

How do you find the accuracy of a ML model?

In which scenario we will prefer recall over precision?

What's up with Turing?
Get the latest news about us here.

Know more about remote work.

Checkout our blog here.

Checkout our blog here.

Have any questions?

We'd love to hear from you.

We'd love to hear from you.

Tell us the skills you need and we'll find the best developer for you in days, not weeks.