Confusion Matrix in Machine Learning

Tanmaya Jain
Analytics Vidhya
Published in
3 min readFeb 23, 2021

So, first thing first. What is Confusion Matrix?

  • In simple terms confusion matrix is a performance measurement for a machine learning problem.

So our main aim in this blog is to understand what is confusion matrix and how to calculate it.

So how does a confusion matrix looks like-

With the help of confusion matrix we can get crucial results(Recall, Precision and so on)about our model.

Note: To understand better I am taking an example of 2 class problem. Say +,-

First let’s understand TP,FP,FN,TN-

TP — True Positive : Your model predicted + and actually its +.

FP — False Positive : Your model predicted + but actually its -.

FN — False Negative : Your model predicted- but actually its +.

TN — True Negative : Your model predicted- and actually its -.

Picture depicting various outcomes.

So, lets begin with calculation part by a simple example -

As per the example we will calculate Recall, Precision and Accuracy-

Recall

So, Recall = 2/3 = 0.66667

  • Out of all the positive classes, how much we predicted correctly. It should be high as possible.

Precision

So, Precision = 2/3 = 0.6667

  • Out of all the positive classes we have predicted correctly, how many are actually positive.

Accuracy

Accuracy = 5/7

Simply means how many we predicted correctly. It should be as high as possible.

F-measure

So, F-measure = 0.6667

  • F-Measure is Harmonic Mean of Recall and Precision.
  • Measure Recall and Precision at same time.

So, I hope I was able to deliver the basics of Confusion Matrix to you.

If you like this post you can motivate me by some 👏.

Lets meet in some other article.

--

--

Analytics Vidhya
Analytics Vidhya

Published in Analytics Vidhya

Analytics Vidhya is a community of Generative AI and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Tanmaya Jain
Tanmaya Jain

Written by Tanmaya Jain

I am BTech student at Delhi Technological University and having deep interest in ML/DL and data science.