For this assignment, I will evaluate a binary classification model that predicts penguin sex. I plan to follow 4 steps:
Start with a baseline: I will look at the distribution of the actual classes using a ggplot2 bar chart and calculate the null error rate.
Compare different thresholds: I will use thresholds of 0.2, 0.5, and 0.8 to create predictions. For each threshold, I will create a confusion matrix showing true positives, false positives, true negatives, and false negatives.
Calculate performance metrics: I will calculate accuracy, precision, recall, and F1 score for each threshold and then compare results to see how changing the threshold affects the model.
Real-world examples: I will look into examples when 0.2 threshold might be useful and when 0.8 makes more sense
We have 54 male and 39 female penguins, so male is the majority class. Since the null model predicts the most common class every time, all 39 female penguins will be classified incorrectly. The null error rate of 41.9% gives us a baseline for evaluating the model. Our model should have a lower error rate than the baseline.
At the 0.2 threshold the model predicted more penguins as female. It correctly identified 37 females, but also incorrectly classified 6 males as female. As the threshold increased the model predicted female less often. At the 0.8 threshold, it correctly identified 36 females and incorrectly classified only 2 males as female.
All three thresholds perform better than the null model. The null error rate is 41.9%, while the model error rates are about 8.6% at the 0.2 threshold, 6.5% at 0.5, and 5.4% at 0.8. This shows that the model performs much better than simply predicting the majority class every time.
Threshold use cases
In penguins dataset at a 0.2 threshold the model correctly identified 37 of 39 female penguins, but also incorrectly identified 6 males as female. So lower threshold can be useful when finding as many positive cases as possible is more important than having some false positives. For example, in medical screening, it can be better to find more patients for additional testing than to miss identifying potentially dangerous condition.
At a 0.8 threshold, only 2 males were incorrectly classified as female. A higher threshold can be useful when false positives are more costly, for example when detecting fraud before blocking a transaction.
In general, choosing threshold should be linked to the context and what type of error we are trying to avoid.