**A confusion matrix** is a table that is used to measure the performance of the machine learning classification model(typically for supervised learning, in the case of unsupervised learning is usually called the matching matrix) where output can be two or more classes. Each row of the **confusion matrix** represents the instances in a predicted class while each column represents the instance in an actual class or vice versa.

**A confusion matrix** is also known as an **error matrix**.

**Also Read:**

- Data Pre-Processing
- What is cross-validation in Machine Learning ?
- Getting started with Machine learning
- Loss Functions| Cost Functions in Machine Learning

In this article, we will be dealing with the various parameters of the confusion matrix and the information that we can extract from it. The structure of the confusion matrix is as shown in the figure below.

Now let’s understand what are **TP, FP, FN, TN**.

Here we have two classes, * Yes *and

**TP-Tru****e****positive**: You predictedclass and its actual class is also*Yes*.*Yes***TN-True negative**: You predictedclass and its actual class is*No*.*No***FP-False positive:**You predicted theclass but actually it belongs to the*Yes*class. It is also called*No*.*type 1 error***FN-False Negative:**You predictedclass but actually it belongs to the**No**class. It is also called a**Yes**.**type II error**

So, what are the classification performance metrics that we can calculate from the confusion matrix? Let’s see.

By observing the confusion matrix we can calculate the *Accuracy*, *Recall*, *Precision, *and **F1-score**(or *F measure*) of the classification model. Let’s understand them by taking an example of a confusion matrix.

Information we obtain from the above confusion matrix:

- There are altogether 165 data points (i.e. observations or objects) and they are classified into two classes
and*Yes*.*No* - Our classification model predicted
times, and*Yes,*110times But according to the actual classification, there are altogether*No,*55**105,**and*Yes***60,***No’s.*

The confusion matrix including the above calculations is as given below,

Now, let’s understand the above metrics in brief.

**Accuracy**:

**ACCURACY = TP + TN / TP + TN + FP + FN**

On the basis of the above confusion matrix, we can calculate the accuracy of the model as,

The **error **of the classification is given as ,

**Precision**: It tells, out of all the classes, how much our classifier predicted correctly. It should be high as possible. In other words, Precision tells us about when it predicts a class, how often is it correct. It is calculated by using the formula below,

**PRECISION= TP / TP + FP **

On the basis of the above confusion matrix, we can calculate the Precision of the model as,

**Recall**: Recall tells us about when it is actually yes, how often does our classifier predict yes. or it can also be defined as, out of all the positive classes, how much our classifier predicted correctly. It is calculated by using the formula below,

**RECALL = TP / TP + FN**

On the basis of the above confusion matrix, we can calculate the Recall of the model as,

**F-measure(F1-Score)**: F-measure(F1-Score) is obtained as the harmonic mean of recall and Precision.It is calculated by using the formula below,

On the basis of the above confusion matrix, we can calculate the F-measure of the model as,

Post a Comment

No Comments