Medium Last updated on May 7, 2022, 1:12 a.m.
F1 Score is a method of evaluation of a classification machine learning model. F1 Score depends on 4 root factors.
1. True Positives (TP) - These are the correctly predicted positive values which mean that the value of the actual class is yes and the value of the predicted class is also yes.
2. True Negatives (TN) - These are the correctly predicted negative values which mean that the value of the actual class is no and value of the predicted class is also no.
False positives and false negatives, these values occur when your actual class contradicts the predicted class.
3. False Positives (FP) – When the actual class is no and the predicted class is yes.
4. False Negatives (FN) – When the actual class is yes but the predicted class is no.
These four parameters can be used to calculate Accuracy, Precision, Recall, and F1 score.
Accuracy - Accuracy is the most intuitive performance measure and it is simply a ratio of correctly predicted observation to the total observations. One may think that, if we have high accuracy then our model is best. Yes, accuracy is a great measure but only when you have symmetric datasets where values of false positive and false negatives are almost the same. Therefore, we have to look at other parameters to evaluate the performance of your model.
$$ Accuracy = \frac{TP+TN}{TP+TN+FP+FN} $$
Precision - Precision is the ratio of correctly predicted positive observations to the total predicted positive observations.
$$ Precision = \frac{TP}{TP+FP} $$
Recall (Sensitivity) - Recall is the ratio of correctly predicted positive observations to all observations in actual class - yes.
$$ Recall = \frac{TP}{TP+FN} $$
F1 score - F1 Score is the weighted average of Precision and Recall. Therefore, this score takes both false positives and false negatives into account. Intuitively it is not as easy to understand as accuracy, but F1 is usually more useful than accuracy, especially if you have an uneven class distribution. Accuracy works best if false positives and false negatives have similar costs. If the cost of false positives and false negatives are very different, it’s better to look at both Precision and Recall.
$$ F1 Score = \frac{2 \times Precision \times Recall}{Precision+Recall} $$