Confusion Matrix is an array used to describe the performance of a classification model in Machine Learning. It is also known as the error matrix. In this article, Iâ€™ll give you an introduction to the Confusion Matrix in Machine Learning.

## What is Confusion Matrix in Machine Learning?

It is a method of evaluating the performance of a classification model. The idea behind this is to count the number of times instances of class 1 are classified as class 2. For example, to find out how many times the classification model has confused the images of Dog with Cat, you use the confusion matrix.

Also, Read â€“ 200+ Machine Learning Projects Solved and Explained.

To calculate the confusion matrix for a given classification model, you must have a set of predicted values so that they can be compared to the set of actual values. You can use it on both test and training sets.

## Lets Understand By Example ðŸ˜ƒ

In Confusion Matrix, each row represents an actual class and each column represents the predicted class. Letâ€™s frame a problem to understand the concept better.

For example, we trained a machine learning model to classify images of dogs from images of animals. Now, after using a confusion matrix on predicted values, we got the output as shown in the table below:

53057 | 1522 |

1325 | 4096 |

So according to the table above, the first row represents non-dog images which are only negative class, where 53057 of these values are correctly classified as non-dog images, these values are known as ** true negatives** in machine learning. The remaining 1522 values in the first row are incorrectly classified as dog images and these values are referred to as

**in machine learning.**

*false positives*Now look at the table above again, the second row of the table represents the values of the images of dog which is the positive class according to the problem statement. Here, 1325 is the number of times the images are classified as non-dog images which are called ** false negatives** in machine learning, and the rest 4096 is the number of times the model predicted them to be true as images of dog, these values are known to be

**in machine learning.**

*true positives*A perfect classification model will only have true positives and true negatives, which means that if the confusion matrix will not have zero values on its primary diagonals, the classification model is perfect as shown below.

54579 | 0 |

0 | 5421 |

I hope you liked this article on what is confusion matrix and what is the concept behind it. Feel free to ask your valuable questions in the comments section below.Â