<aside> 💡
Precision and recall are key metrics for evaluating the performance of a logistic regression model, especially when dealing with imbalanced datasets where accuracy alone can be misleading.
</aside>
These metrics are derived from the confusion matrix and help assess how well the model distinguishes between the two classes.
Precision (also called Positive Predictive Value) measures the proportion of correctly predicted positive cases out of all predicted positives:
$$ Precision = \frac{TP}{TP + FP} $$
A high precision means that when the model predicts a positive outcome, it is usually correct. This is critical in applications where false positives are costly, such as fraud detection or spam filtering (where you don’t want to wrongly classify a legitimate email as spam).
Recall (also known as Sensitivity or True Positive Rate) measures the proportion of actual positives that were correctly predicted:
$$ Recall = \frac{TP}{TP + FN} $$
A high recall means the model correctly identifies most of the actual positive cases, which is important in scenarios like medical diagnosis, where failing to detect a disease (false negative) can have serious consequences.
There is often a trade-off between precision and recall, as increasing one may decrease the other. The F1-score, defined as the harmonic mean of precision and recall, helps balance both:
$$ F1 = 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}} $$
A well-calibrated logistic regression model finds the right balance based on the problem at hand. For example:
By tuning the classification threshold, we can optimize for either precision or recall, depending on the specific requirements of the task.