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.
Now let’s understand what are TP, FP, FN, TN.
Here we have two classes Yes and No, then we define,
- TP-True positive: You predicted Yes class and its actual class is also Yes.
- TN-True negative: You predicted No class and its actual class is No.
- FP-False positive: You predicted Yes class but actually it belongs to No class. It is also called type 1 error.
- FN-False Negative: You predicted No class but actually it belongs to Yes class. It is also called type II error.
|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 Yes and No.
- Our classification model predicted Yes, 110 times, and No, 55 times But according to the actual classification, there are all together 105, Yes and 60, No’s .
|Confusion matrix 2|
Now, let’s understand above metrics in brief.
- Accuracy: The accuracy of classification can be obtained by using the formula below,
Confusion matrix- Accuracy
- 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
- 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
- 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)