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.

PythonRuns entirely in your browser — nothing is sent to a server.

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.

PythonRuns entirely in your browser — nothing is sent to a server.

Practice Questions

Question 1

For Visa's fraud detection, why is Recall more important than Precision?

  • Because Recall sounds more professional
  • Because missing actual fraud (False Negative) is far more costly than occasionally blocking a legitimate transaction (False Positive)
  • Because Precision only works with numbers
  • Because Recall is faster to compute

Question 2

What is the purpose of Grid Search in hyperparameter tuning?

  • To search for files on the computer
  • To systematically try all combinations of hyperparameters and find the configuration that produces the best model performance
  • To delete unused parameters
  • To reduce the size of the dataset