Model Evaluation Part 1
Explore key evaluation metrics for classification models in machine learning, including confusion matrix components, accuracy, precision, recall, and F1-score. Understand their calculations and how to interpret these measures for both binary and multi-class classification tasks.
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 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
1defines the function to calculate the values inside a confusion matrix. -
Lines
12to20calculates the values which are present inside a confusion matrix. Things to be learned are the logic used to calculate the values. -
On Line
27and Line28, we print the actual and the predicted class labels. -
From Line
29to Line32we are printing the respective statistics.
Accuracy
Accuracy is calculated as the ratio of the correctly classified instances and the total number of instances.
...