Once a ML model is trained, (like predicting who will buy a product or whether a message is spam), then we are required to measure the performance of the model. This helps in deciding if the model is accurate and reliable. In this section, we will explore four important performance metrics with simple definitions and examples.
6.5.1 Confusion Matrix
A confusion matrix is a simple table that shows how many predictions/ classifications were correct or incorrect.
Table 6.6 shows a simple confusion matrix considering whether a student will pass or fail (classification problem).
Table 6.6: Confusion Matrix
| Predicted: pass | Predicted: fail | |
|---|---|---|
| Actual: pass | True Positive (TP) | False Negative (FN) |
| Actual: fail | False Positive (FP) | True Negative (TN) |
TP Model predicted pass, and the student was pass in actual as well. TN Model predicted fail and the student failed in actual as well. FP Model predicted pass, but the student failed in actual. FN Model predicted fail and the student was pass in actual.
The confusion matrix helps in understand whether a model is making classification or prediction mistakes and helps in calculating the accuracy (an important measure) of the model.