
r/DevDepth

How to prevent overfitting in your ML models — a practical checklist
Overfitting is one of the most common problems beginners hit when training machine learning models. Your training accuracy looks great but validation accuracy tanks. Here's how to fix it.
**What's actually happening:**
Your model is memorising the training data instead of learning patterns. It works perfectly on data it's seen, and fails on anything new.
**Practical fixes in order of ease:**
**Get more data** — The most reliable fix. Overfitting shrinks when your dataset grows.
**Simplify your model** — Fewer layers, fewer neurons, fewer features. Start simple and add complexity only when needed.
**Regularisation** — Add L2 (Ridge) or L1 (Lasso) penalties to your loss function. In Keras: `kernel_regularizer=l2(0.001)`
**Dropout** — Randomly deactivate neurons during training. Add `Dropout(0.3)` after dense layers.
**Early stopping** — Stop training when validation loss stops improving:
`EarlyStopping(patience=5, restore_best_weights=True)`
- **Cross-validation** — Use k-fold CV instead of a single train/test split to get a honest picture of performance.
**Quick diagnostic:** Plot your training vs validation loss over epochs. If training loss keeps falling while validation loss rises, you're overfitting.
Which of these has worked best for you?