In order to tackle the preceding problem, it is possible to utilize a confusion matrix. Confusion matrices present the number of instances correctly or incorrectly predicted as each possible class. In a dataset with only two classes (Yes and No), a confusion matrix has the following form:
n = 200 |
Predicted: Yes |
Predicted: No |
Target: Yes |
80 |
70 |
Target: No |
20 |
30 |
There are four cells, each corresponding to one of the following:
- True Positives (TP): When the target belongs to the Yes class and the model predicted Yes
- True Negatives (TN): When the target belongs to the No class and the model predicted No
- False Positives (FP): When the target belongs to the No class and the model predicted Yes
- False Negatives (FN): When the target belongs to the Yes class and the model predicted No
Confusion matrices provide information about the balance of the true and predicted classes. In order to calculate the accuracy from a confusion matrix, we divide the sum of TP and TN by the total number of instances: