Precision, Recall & F1
Understanding the difference between catching every positive case and avoiding false alarms.
Precision and Recall Explained Simply
Imagine you are fishing with a net:
- Precision: Out of all the fish you caught in your net, what percentage are actually the target fish you wanted? High precision means very few unwanted items ended up in your net.
- Recall: Out of all the target fish swimming in the lake, what percentage did your net manage to catch? High recall means very few target fish escaped.
The Simple Math
Precision = True Positives / (True Positives + False Positives)
Recall = True Positives / (True Positives + False Negatives)
F1 Score = 2 * (Precision * Recall) / (Precision + Recall)
Precision looks at everything your model flagged positive. Recall looks at everything that was actually positive in reality.
The Tradeoff and Thresholds
Most classification models output a confidence probability number between 0 and 1.
Changing the decision threshold changes your metrics:
- Lowering the threshold flags more items. Recall goes up, but precision goes down because you get more false alarms.
- Raising the threshold flags fewer items. Precision goes up because you are very pick, but recall goes down because you miss things.
You choose this threshold based on business needs rather than defaulting to 0.5.
Which Metric Matters More?
Ask yourself which error hurts more in your application.
- Cancer Screening: Missing a tumor is dangerous. Optimize for Recall. A false alarm just means one extra follow up test.
- Spam Filtering: Deleting an important real email is terrible. Optimize for Precision. It is better to let a little spam into the inbox than delete a real message.
- Automated Account Bans: Banning an innocent user destroys trust. Optimize for Precision.
Say this out loud
Precision tells me how often the model is right when it makes a positive claim. Recall tells me what fraction of real positive cases the model managed to find. Which one to optimize depends on which mistake costs more in the real product. If missing a case is dangerous, I focus on recall. If false alarms destroy user trust, I focus on precision.
Followups to expect
- Does bagging lower bias or variance? Bagging lowers variance by averaging predictions from many independent models. Boosting lowers bias by building models step by step.
- Why use macro versus micro averaging in multiclass problems? Macro averaging treats all classes equally regardless of size, which is great when rare classes matter. Micro averaging pools all predictions globally, which is dominated by large classes.
Check yourself
A model flags 100 transactions as fraud and 30 of them are actually fraud. There were 60 total frauds in the dataset. What are precision and recall?