Confusion Matrix

The following two tabs change content below.
I am a technology enthusiast and always up for challenges. Recently I have started getting hands dirty in machine learning using python and aspiring to gather everything I can.

Latest posts by Renuka Joshi (see all)

We learned different types of classification in previous tutorials.In those tutorials we counted number of right and wrong predictions manually.This counting  by using Confusion Matrix.In this tutorial we will learn about confusion matrix  and how this operation can be performed on predictions and actual results using python.

Confusion Matrix

According to Python documentation,

confusion matrix C is such that Ci,j is equal to the number of observations known to be in group i but predicted to be in group j.Thus in binary classification, the count of true negatives is C0,0 , false negatives is C1,0, true positives is C1,1 and false positives is C0,1.


Consider the same problem statement as previous tutorials. We wanted to determine whether a user will buy car or not. We can compare predictions against actual results by using confusion_matrix.


As we have already explained whole code till in each classification article, we will only focus on confusion matrix.

  • we imported confusion_matrix() from sklearn.metrics
  • compared y_test with y_pred by using confusion_matrix(y_test, y_pred)

Execute whole program and check cm variable in variable explorer.

confusion matrix

confusion matrix


  • C0,0: true negatives
  • C1,0: false negative
  • C1,1: true positives
  • C0,1 : false positives

Total 11 predictions are wrong out of 100.Thus,we can use confusion matrix to compare predictions against test results.Happy learning!



Share Button

1 comment for “Confusion Matrix

Leave a Reply

Your email address will not be published. Required fields are marked *