Model Evaluation: Part 1
Explore important classification model evaluation metrics including the confusion matrix, accuracy, precision, recall, and F1 score. Understand how these measures help assess your model's performance and their applications in binary and multi-class classification. This lesson equips you to calculate and interpret these evaluation statistics effectively.
Model evaluation measures
In this lesson, we will observe model evaluation for classification. We predict a discrete-valued output, and it has its own evaluation measures.
Confusion matrix
The confusion matrix serves as an evaluation measure for classification problems. The confusion matrix for a binary classification problem having only two class labels (0 and 1) would look like this:
| Actual Class Label (1) | Actual Class Label (0) | |
|---|---|---|
| Predicted Class Label (1) | TP | FP |
| Predicted Class Label (0) | FN | TN |
Here
TP (True Positive): We predicted a positive Class Label (1), and it is True.
TN (True Negative): We predicted a negative Class Label (0), and it is True.
FP (False Positive): It is also called Type 1 Error. We predicted a positive Class Label (1), and it is False.
FN (False Negative): It is also called a Type 2 Error. We predicted a negative Class Label (0), and it is True.
Note that positive and negative refer to the predicted class labels, whereas True and False refer to the actual class labels.
This confusion matrix is the basis of many evaluation measures we are calculating below:
-
Line 1 defines the function to calculate the values inside a confusion matrix.
-
Lines 12 to 20 calculate the values that are present inside a confusion matrix. Things to be learned are the logic used to calculate the values.
-
Lines 27 and 28, print the actual and the predicted class labels.
-
Lines 29 to 32 print the respective statistics.
Accuracy
Accuracy is calculated as the ratio of the correctly classified instances and the total number of instances.
...