Model Evaluation & Optimization
Beyond Accuracy: The Metrics That Matter
A model with "95% accuracy" sounds impressive—until you learn that 95% of transactions are legitimate anyway. For **Visa**, the only metric that matters is: "Did we catch the fraud?" This chapter teaches you to think beyond simple accuracy.
We explore the **Confusion Matrix**, **Precision vs. Recall**, and the **F1 Score**. Then we tackle **Hyperparameter Tuning** with Grid Search to find the optimal settings for **Walmart's** demand forecasting model.
The Confusion Matrix: Truth vs. Prediction
The **Confusion Matrix** breaks down predictions into four categories: True Positives (correctly caught fraud), True Negatives (correctly cleared legit), False Positives (falsely blocked a user), and False Negatives (missed a fraud). For **Visa**, a False Negative is catastrophic—it means a fraudster got through.
Precision, Recall & the F1 Score
**Precision** answers: "Of all transactions I flagged as fraud, how many were actually fraud?" **Recall** answers: "Of all actual fraud cases, how many did I catch?" For **Visa**, high Recall is more important—missing a fraud is worse than a false alarm. The **F1 Score** balances both.
Hyperparameter Tuning: Grid Search
Every ML model has "knobs" (hyperparameters) that control its behavior. For **Walmart's** demand forecaster, this might be the learning rate or tree depth. **Grid Search** systematically tries every combination to find the best one.
Practice Questions
Question 1
For Visa's fraud detection, why is Recall more important than Precision?
Question 2
What is the purpose of Grid Search in hyperparameter tuning?