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.
 What the confusion matrix is and why you need it?
 Other Important Terms
 Why you need a Confusion matrix?
 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:
 True Positive and Interpretation: It’s true and you predicted positive.
 False Positive and Interpretation: It’s false and you predicted positive.
 True Negative and Interpretation: It’s true and you predicted negative.
 False Negative and Interpretation: It’s false and you predicted negative.
2) Other Important Terms:
 True Positive/Recall/Sensitivity Confusion Matrix: Sensitivity Confusion Matrix equal to True Positive divided by True Positive & False Negative.
 True Negative/Specificity Confusion Matrix: Specificity Confusion Matrix equal to True Negative divided by True Negative & False Positive.
 Positive Predictive/Precision Confusion Matrix: Precision Confusion Matrix equal to True Positive divided by True Positive & False Positive.
 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:
 It gives knowledge not just into the errors which are made by a classifier yet to addition mistakes that are being made.
 Each row of the confusion matrix addresses the occasions of the real class.
 Each column of the confusion matrix addresses the cases of that anticipated class.
 This breakdown encourages you to defeats the impediment of utilizing classification precision alone.
 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.
 It shows how any classification model is confused when it makes forecasts.
4) How to calculate Confusion Matrix
Here, is a stepbystep measure for figuring a confusion matrix:
 In the first place, you need to test the dataset with its normal result esteems.
 Anticipate all the lines in the test dataset.
 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 stepbystep measure for figuring a 2 Class Confusion Matrix:
We should imagine we have a twoclass 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:
 Cat classified as Cat: 3
 Dog classified as Dog: 3
Computation of incorrect predictions:
 Cat classified as Dog: 2
 Dog classified as Cat: 2
2class confusion matrix:
Cat  Dog  
Cat  3  2 
Dog  3  2 
Confusion matrix above answer:
 The total actual cat in the matrix is the sum of the cat column (3 3)
 The total actual dog in the matrix is the sum of the dog column (2 2)
 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:
 Expected = [10, 10, 20, 10, 20, 20, 10, 20, 20, 20]
 Predicted = [10, 20, 20, 10, 20, 20, 10, 10, 10, 20]
 results = confusion_matrix (expected, predicted)
 print (results)
Confusion matrix array:
[[4 2]
[1 3]]
Conclusion
Confusion Matrix is very useful for measuring the AUCROC 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
PEOPLE ALSO READ

PotpourriJigsaw Academy is the #1 Analytics Training Institute in India

Articles“I Would Recommend This Course To Anyone Who’s Interested In Pursuing Business Analytics” – That’s What Our Learners Say!

ArticlesChannel Your Inner Business Analyst With The Right Upskilling Program

ArticlesAI needs Diversity to reduce Gender and Racial Bias!

ArticlesWhen Is The Best Time To Build A Career In Data Science You Ask? – We Say NOW!