Confusion Matrix — Is It Confusing?🙄🙄Its use-case in Security world

VinayGupta
3 min readJun 5, 2021

--

Everything You Should Know about Confusion Matrix

Actually in ML, Sometimes we are in some situation where our expectation is at High but our ML model makes us sad..! Your all code of ML is absolutely right but you don’t know Where the model goes wrong?🧐

And if you really want to know what's happened behind , Here confusion matrix comes in the role.

In this article, Confusion matrix is not just a matrix, but it provides lots of information about our model.

What is a Confusion Matrix?

First of all its not confusing…!😅

A Confusion matrix is an N x N matrix used for evaluating the performance of a classification model, where N is the number of target classes. For a binary classification problem, we would have a 2 x 2 matrix.

Let’s Understand Confusion matrix with the help of example.

Suppose, We’ve 100 mails & you’ve created one model that tells us if any Email from dataset is spam or not…!

Let’s understand the terminology :

1. True Positive (TP):

The predicted value matches the actual value

The actual value was positive and the model predicted a positive value (means model predicted 45 mails as Spam & actually they was Spam.

2. False Positive (FP):

The predicted value was falsely predicted

The actual value was negative but the model predicted a positive value (means model predicted 5 mails as Spam & but actually they wasn’t Spam)

Also known as the Type 1 error

3. False Negative (FN)

The predicted value was falsely predicted

The actual value was positive but the model predicted a negative value (means model predicted 20 mails as Non-spam & but actually was Spam)

4. True Negative (TN)

The predicted value matches the actual value

The actual value was negative and the model predicted a negative value (means model predicted 30 mails Non-spam & really wasn’t Spam)

Also known as the Type 2 error

Why we need a Confusion Matrix?

In above example, let’s test accuracy — (45+30)/(45+20+5+30) = 75%(moderate !)

Here, our model says that “I can predict 75% mail as spam from all mails”. We can say its good but now there comes Type-2 Error. ⚡⚡ (means our model couldn’t predict 30 mails as Spam & you know WHAT CAN HAPPEN…!)

So, from confusion matrix you can get the value of Type-1 Error & Type-2 Error and by this values you can get more information about your ML model.

Also we can get info of Precision, Recall, Sensitivity…etc.(This we will see in future.)

⭐Thanks for reading…!⭐

--

--

VinayGupta
VinayGupta

Written by VinayGupta

Hey..! I'm Vinay Gupta, on the way of learning new technologies.

No responses yet