# What is confusion matrix?

**Confusion matrix** is a table that is used to measure the performance of the machine learning classification model(typically for supervised learning, in case of unsupervised learning it usually called 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.

**Confusion matrix** is also known as **error matrix**.

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

Confusion matrix |

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

Here we have two classes * Yes *and

**, then we define,**

*No***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 predictedclass but actually it belongs to*Yes*class. It is also called*No*.*type 1 error***FN-False Negative:**You predictedclass but actually it belongs to**No**class. It is also called**Yes**.**type II error**

**,**

*Accuracy***,**

*Recall***and**

*Precision**(or*

**F1-score****) of the classification model. Let’s understand them taking an example of confusion matrix.**

*F measure*Confusion matrix 1 |

Information we obtain from above confusion matrix:

- There are all together 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 all together*No,*55**105,**and*Yes***60,***No’s .*

Confusion matrix 2 |

Now, let’s understand above metrics in brief.

- Accuracy:

Confusion matrix- Accuracy

**Accuracy**= (100+50) /(100+5+10+50)= 0.90

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

**Error = 1- Accuracy = 1 – 0.90 = 0.1.****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,

Confusion matrix – Precision

**Precision**= 100/ (100+10)=0.91

**Recall**: Recall tells us about when it is actually yes, how often does our classifier predicted 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,

Confusion matrix- Recall

**Recall**= 100/(100+5)=0.95

**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,

Confusion matrix- F-measure(F1-Score)

**F-measure**=(2*Recall*Precision)/(Recall+Presision)

Pingback:What is F1-score and what is it's importance in Machine learning? | KRAJ Education