CLASSIFICATION REPORT
You might have already come across some classification report like this
Let's discuss this report in detail
Classes
0, 1, 2 are the three different classes
Support
Support is nothing but the number of test samples available for testing
In this exampleTotal test samples available = 100Test samples that belong to class 0 = 39Test samples that belong to class 1 = 27Test samples that belong to class 2 = 34
Precision
Suppose with the help of the learning algorithm, you have predicted that 31 out of those 100 test samples belong to class 0
Only 11 of those 31 samples you predicted that belong to class 0 are actually belongs to class 0
So those 11 are considered as true positives because they are correctly classified that they belong to class 0 and the rest are considered as false positives because we predicted them that they belong to class 0 but they don’t belong to class 0
True Positives = TP = 11False Positives = FP = 20Precision = (TP)/(Total samples that were predicted as positives)Precision = (TP)/(TP + FP)Precision = 11/31 = 0.35
Recall
There are 39 samples that belong to class 0
Suppose with the help of the learning algorithm, we have predicted that 11 out of those 39 samples belong to class 0
11 → True Positives
28 of them are predicted that they don’t belong to class 0 but they actually belong to class 0
28 → False Negatives
True Positives = 11False Negatives = 28Recall = TP/Total samples that were actually positiveRecall = TP/(TP + FN)Recall = 11/39 = 0.28
F1-Score
F1-score provides a relationship between precision and recall. So this helps us in quantifying our learning algorithm better and brings balance between precision and recall
f1-score = (2 * precision * recall) / (precision + recall)
If either precision or recall is pretty small, f1-score is going to be pretty small
precision of class 0 = 0.35recall of class 0 = 0.28f1-score = (2 * 0.35 * 0.28) / (0.35 + 0.28) = 0.31
Accuracy
Total number of samples that are classified into the right correct classes with the help of the learning algorithm
Total test samples → 100
Samples that are classified into the correct class with the help of our learning algorithm → 30
accuracy = 30/100 = 0.3
Macro Average
Compute the average without considering the proportion
precision_class_0 = 0.35precision_class_1 = 0.24precision_class_2 = 0.33macro-avg precision = (0.35 + 0.24 + 0.33)/3
Weighted Average
Compute the average considering the proportion
precision_class_0 = 0.35precision_class_1 = 0.24precision_class_2 = 0.33samples_class_0 = 39samples_class_1 = 27samples_class_2 = 34total_samples = 100proportion_class_0 = 39/100 = 0.39proportion_class_1 = 27/100 = 0.27proportion_class_2 = 34/100 = 0.34w-avg precision = ((0.35 * 0.39) + (0.24 * 0.27) + (0.33 * 0.34))
Similarly the calculations of macro-avg recall, weighted-avg recall, etc. can be done