# Precision, Recall & Confusion Matrices in Machine Learning

You’ve developed an machine-learning model. Great. You input your inputs and it will give you an output. Sometimes the output is accurate and other times it’s wrong. You can tell that the model predicts with an 86% accuracy since the results of the test you took to train it said that.

However 86% isn’t an adequate metric of accuracy. If you use it, you only get half the truth. Sometimes, it gives an incorrect impression. Recall, precision and confusion matrix…now this is safer. Let’s look at the matrix.

## Confusion matrix

Each of accuracy as well as recall are derived using the confusion matrix therefore we begin there. The confusion matrix can be utilized to illustrate the accuracy of a model in making its predictions.

### Binary classification

Let’s examine an illustration: A model is employed to predict the likelihood that a driver will turn right or left at a traffic light. This is an example of a binary classification. It is able to work on any prediction task that can make either a no or yes (or false or true) distinction.

The aim for the confusion matrix is demonstrate how…well the model is the model is muddled the model can be. To accomplish this we will introduce the concepts of False negatives as well as fake negatives.

• If the model’s goal is to determine that the model will predict the negative (left) in addition to it is predicted to predict the negative (right) that is, that False Positive predicts left, but the real orientation is to the right.
• The concept of a false positive is a false positive that works in the opposite direction and the model predicts right however the actual outcome is left.

By using a confusion matrix these numbers can be displayed in the chart like this:

In this matrix of confusion There 19 predictions that are made. 14 are correct , and 5 are incorrect.

• This False negative cell number 3 indicates that the model predicted that it would be negative, but it actually was positive.
• This False Positive Cell, number 2 signifies that the model was predicted to be as a positive outcome, but it was actually negative.

The false positive can be a hindrance to the decision a person decides to take at this point. If, however, you added an element of risk to the decision that would lead to an enormous reward and choosing wrongly could lead to certain death, then there is a stake on the choice, and a false negative could prove to be extremely expensive. We’d prefer the model to make the choice if absolutely certain that it was the correct choice.

### Cost-benefit and benefits of confusion

The balance between the costs and benefits of a variety of options provides some meaning for the matrix of confusion. The Instagram algorithm has to apply the nudity filter in every picture that users post and a nude picture classification algorithm is developed to identify any nudity. If a photo that is not nude gets posted and is able to pass the filter, it can cost a lot to Instagram. They are likely to attempt to classify more items than they need to filter out every photo that is not nude since the price of failing is that high.

### Non-binary classification

In the end, confusion matrices do not only apply to binary classifiers. They can be utilized on any of the categories that the model requires and the same principles of analysis apply. For example an analysis matrix could be used to categorize people’s views of debates like the Democratic National Debate:

• Very poor
• Poor
• Neutral
• Good
• Excellent

All of the predictions that the model will make are incorporated into a matrix of confusion:

## Precision

Precision is the proportion to genuine positives to the sum of true positives as well as false positives. Precision measures the amount of junk positives mixed in. If there’s no negatives (those FPs) and the model is 100% accurate, then it was 100% accurate. The more FPs that are included in this mix, the worse this precision will appear.

To determine the model’s accuracy We need to know the negative and positive figures from the matrix of confusion.

Specification = TP/(TP + FP)

## Recall

Recall is a different approach. Instead of focusing on the amount of false positives that the model predicted, the recall study examines the amount of false negatives that were added to the mix of predictions.

Recall = TP/(TP + FN)

The rate of recall is penalized when the prediction of a false negative occurs. Because the penalties associated with recall and precision are both opposites as are the equations. Recall and precision are the yin and Yang of measuring the complexity matrix.

## Recall vs. precision Which is better?

As we’ve seen in the context of understanding the matrix of confusion, there are times when models might wish to allow additional false positives pass through. This could result in greater accuracy since false negatives don’t impact the recall equation. (There is a good reason for them to be there.)

Sometimes, a model may want to let additional false positives pass which results in greater recall since false positives aren’t accounted for.

In general, a model can’t be both highly recall-able as well as high accuracy. There is a price to be paid when you get higher levels of accuracy or recall. The model might be at an equilibrium point, where recall and precision are equal, however when the model is modified to increase a few percentage points of precision, it will reduce the rate of recall.