When we use regularization to prevent overfitting, the key metrics to watch are validation loss and validation accuracy. These metrics tell us how well the model performs on new, unseen data. Regularization helps the model avoid memorizing training data, so a lower validation loss and higher validation accuracy mean the model is generalizing better.
Why regularization prevents overfitting in TensorFlow - Why Metrics Matter
Confusion Matrix Example (Validation Data):
Predicted
Pos Neg
Actual
Pos 85 15
Neg 10 90
Total samples = 85 + 15 + 10 + 90 = 200
Precision = TP / (TP + FP) = 85 / (85 + 10) = 0.894
Recall = TP / (TP + FN) = 85 / (85 + 15) = 0.85
This confusion matrix shows a balanced model that generalizes well, likely due to regularization preventing overfitting.
Regularization helps balance precision and recall by preventing the model from fitting noise in training data.
- Without regularization: The model may memorize training examples, leading to very high precision but low recall on new data (missing many true positives).
- With regularization: The model generalizes better, improving recall while maintaining good precision.
For example, in spam detection, regularization helps the model avoid marking too many good emails as spam (false positives), improving precision, while still catching most spam emails (high recall).
Good metrics with regularization:
- Validation loss decreases and stabilizes.
- Validation accuracy is close to training accuracy.
- Precision and recall are balanced (e.g., both above 80%).
Bad metrics without regularization:
- Validation loss is much higher than training loss (sign of overfitting).
- Validation accuracy is much lower than training accuracy.
- Precision or recall is very low, showing poor generalization.
- Accuracy paradox: High accuracy can be misleading if data is imbalanced. Regularization helps but always check precision and recall.
- Data leakage: If validation data leaks into training, metrics look good but model fails in real use.
- Overfitting indicators: Large gap between training and validation loss or accuracy means overfitting, which regularization aims to fix.
Your model has 98% accuracy but 12% recall on fraud detection. Is it good for production? Why not?
Answer: No, it is not good. The low recall means the model misses most fraud cases, which is dangerous. Even with high accuracy, the model fails to catch fraud. Regularization alone won't fix this; you need to improve recall by adjusting the model or data.