Confusion Matrix – A Comprehensive Guide (2021)

img
Ajay Ohri
Share

Introduction

A confusion matrix in machine learning or ML is a method for summing up the presentation of a classification algorithm. Classification precision alone can be deluding on the off chance that you have an inconsistent number of perceptions in each class or if you have multiple classes in your dataset.

Computing a confusion matrix can give you a superior thought of what your classification model is getting right and what sorts of mistakes it is making.

  1. What the confusion matrix is and why you need it?
  2. Other Important Terms
  3. Why you need a Confusion matrix?
  4. How to calculate Confusion Matrix

1) What the confusion matrix is and why you need it?

A confusion matrix is a presentation estimation procedure for ML classification. It is a sort of table that causes you to know the exhibition of the classification model on a collection of test data for that the true values are known. The term confusion matrix itself is exceptionally basic, yet its connected wording can be a bit complicated.

The classification matrix is a convenient tool for the assessment of statistical models and is now and again alluded to as a confusion matrix. A classification matrix is a significant tool for surveying the consequences of forecast since it makes it straightforward and represents the impacts of wrong expectations.

Actual Values

Predicted Values
  Positive Negative
Positive True Positive False Positive
Negative False Negative True Negative

Confusion matrix interpretation:

  1. True Positive and Interpretation: It’s true and you predicted positive.
  2. False Positive and Interpretation: It’s false and you predicted positive.
  3. True Negative and Interpretation: It’s true and you predicted negative.
  4. False Negative and Interpretation: It’s false and you predicted negative.

2) Other Important Terms:

  1. True Positive/Recall/Sensitivity Confusion Matrix: Sensitivity Confusion Matrix equal to True Positive divided by True Positive & False Negative.
  2. True Negative/Specificity Confusion MatrixSpecificity Confusion Matrix equal to True Negative divided by True Negative & False Positive.
  3. Positive Predictive/Precision Confusion MatrixPrecision Confusion Matrix equal to True Positive divided by True Positive & False Positive.
  4. False Positive: False Positive Confusion Matrix equal to False Positive divided by False Positive & True Negative.

3) Why you need a Confusion matrix?

Here are the advantages of utilizing a confusion matrix:

  1. It gives knowledge not just into the errors which are made by a classifier yet to addition mistakes that are being made.
  2. Each row of the confusion matrix addresses the occasions of the real class.
  3. Each column of the confusion matrix addresses the cases of that anticipated class.
  4. This breakdown encourages you to defeats the impediment of utilizing classification precision alone.
  5. The confusion matrix does not just give you knowledge into the mistakes being made by your classifier yet also the kinds of errors that are being made.
  6. It shows how any classification model is confused when it makes forecasts.

4) How to calculate Confusion Matrix

Here, is a step-by-step measure for figuring a confusion matrix:

  1. In the first place, you need to test the dataset with its normal result esteems.
  2. Anticipate all the lines in the test dataset.
  3. Compute the normal predictions and outcomes:

i.) The sum of the correct expectations for each class.

ii.) The sum of incorrect expectations of each class.

Here, is a step-by-step measure for figuring a 2 Class Confusion Matrix:

We should imagine we have a two-class classification issue of predicting whether a photo contains a cat or a dog. 

We have a test dataset of ten records with anticipated results and a set of expectations from our classification algorithm.

                                                                           Confusion Matrix Table

Expected Predicted
Cat Dog
Cat Cat
Dog Dog
Cat Cat
Dog Cat
Dog Dog
Dog Dog
Dog Cat
Cat Dog
Cat Cat

The algorithm made 6 of the 10 predictions correct with an exactness of 60%.

Accuracy = Total Correct Predictions divided by Total Predictions made multiplied by 100

Accuracy = 6/ 10 * 100

Be that as it may, what sort of mistakes were made? 

We should transform our outcomes into a confusion matrix.

In the first place, we should ascertain the number of correct predictions for each class:

Computation of correct predictions:

  1. Cat classified as Cat: 3
  2. Dog classified as Dog: 3

Computation of incorrect predictions:

  1. Cat classified as Dog: 2
  2. Dog classified as Cat: 2

                                                                                         2-class confusion matrix:

  Cat Dog
Cat 3 2
Dog 3 2

Confusion matrix above answer:

  1. The total actual cat in the matrix is the sum of the cat column (3 3)
  2. The total actual dog in the matrix is the sum of the dog column (2 2)
  3. Correct value in a diagonal line of the matrix (3 2)

The use of a confusion matrix is to depict the exhibition of a classification model on a bunch of test data for which the true values are known. The confusion matrix itself is generally easy to see, yet the connected phrasing can be complex.

Confusion matrix sklearn:

  1. Expected = [10, 10, 20, 10, 20, 20, 10, 20, 20, 20]
  2. Predicted = [10, 20, 20, 10, 20, 20, 10, 10, 10, 20]
  3. results = confusion_matrix (expected, predicted)
  4. print (results)

Confusion matrix array:

[[4 2]

[1 3]]

Conclusion

Confusion Matrix is very useful for measuring the AUC-ROC Curve, Accuracy, Specificity, Precision, and Recall. The confusion matrix presents the manners by which your classification model is confused when it executes predictions.

There are no right or wrong ways of learning AI and ML technologies – the more, the better! These valuable resources can be the starting point for your journey on how to learn Artificial Intelligence and Machine Learning. Do pursuing AI and ML interest you? If you want to step into the world of emerging tech, you can accelerate your career with this Machine Learning And AI Courses by Jigsaw Academy.

ALSO READ

Related Articles

loader
Please wait while your application is being created.
Request Callback