ML Common Pitfalls: Data Leakage, Overfitting, and Mistakes to Avoid
Avoid the top 15 ML pitfalls including data leakage, wrong metrics, overfitting, training/serving skew, and model drift. Learn how to detect each pitfall and fix it with practical examples.
ML Common Pitfalls: Data Leakage, Overfitting, and Mistakes to Avoid
Machine learning projects fail for predictable reasons. This guide covers the top 15 pitfalls organized by category: data, model, evaluation, and deployment. For each, you'll learn what it is, why it's dangerous, how to detect it, and how to fix it.
---
DATA Pitfalls
1. Data Leakage
What it is: Information from outside the training set (often from the future or target) influences the model in a way that would not exist at prediction time.
Why it's dangerous: Models achieve unrealistic performance during development, then fail badly in production. You may deploy a model that cannot generalize.
Types of leakage:
| Type | Example | Fix |
|---|---|---|
| Preprocessing before split | Scaling/normalizing using stats from the full dataset (including test) | Split first, fit scaler on train only, transform train and test separately |
| Target leakage | Using a feature that directly or indirectly reveals the target (e.g., "totalpayment" when predicting "willpay") | Remove features that wouldn't be available at prediction time |
| Temporal leakage | Using future data to predict the past (e.g., using tomorrow's price to predict today) | Ensure train/test split respects time order; never use future features |
How to fix: Always split (or create folds) first. Fit preprocessing (scaling, imputation, encoding) on training data only. Apply the fitted transformers to validation/test. For time series, use expanding or sliding window validation.
---
2. Not Enough Data
What it is: Training on too few samples for the model complexity or problem difficulty.
Why it's dangerous: High variance, overfitting, unstable results. Deep learning and complex models need sufficient data.
How to detect: Learning curves show validation error not stabilizing; small changes in data cause large changes in model behavior.
How to fix: Use simpler models (fewer parameters), more regularization, or collect more data. Rule of thumb: aim for at least 10× more samples than features for linear models; 1000+ samples for tree ensembles; 10K+ for neural networks on non-trivial tasks.
---
3. Ignoring Data Quality
What it is: Missing values, duplicates, outliers, wrong encodings, or corrupt labels left unaddressed.
Why it's dangerous: Models learn noise, biases, or spurious patterns. Predictions become unreliable.
How to detect: EDA (exploratory data analysis), null counts, duplicate checks, distribution plots, outlier detection. Validate labels with domain experts.
How to fix: Handle missing values (impute, drop, or model), remove or correct duplicates, treat outliers (winsorize, remove, or model), validate encodings (e.g., date formats), and clean labels.
---
4. Not Exploring Data First
What it is: Jumping straight to modeling without understanding distributions, correlations, and data quirks.
Why it's dangerous: Wrong assumptions (e.g., linear when relationship is nonlinear), inappropriate algorithms, missed feature engineering opportunities, overlooking leakage or bad quality.
How to detect: You can't detect it — it's a process gap. If you haven't done EDA, you're at risk.
How to fix: Always do EDA first: distributions, missing values, correlations, target vs feature relationships, outliers, temporal patterns. Use visualizations and summary statistics.
---
MODEL Pitfalls
5. Wrong Metric
What it is: Optimizing a metric that doesn't match the business objective (e.g., accuracy for imbalanced fraud detection).
Why it's dangerous: You build a model that looks good by the wrong measure but fails in practice. A "99% accurate" fraud model that catches no fraud is useless.
How to detect: Compare model decisions to business outcomes. If stakeholders care about recall but you optimized accuracy, you have a mismatch.
How to fix: Choose metrics based on real-world cost of errors. Use F1, AUC-PR, or recall for imbalanced classification; use MAE/RMSE with the right emphasis for regression. Document why you chose each metric.
---
6. Overfitting
What it is: Model fits training data too closely, including noise, and fails to generalize.
Why it's dangerous: Great training metrics, poor production performance. Wasted time and false confidence.
How to detect: Large gap between train and validation/test performance. Learning curves show train error much lower than validation.
How to fix: More data, simpler model, regularization (L1/L2), early stopping, cross-validation, feature selection. See the [Bias-Variance Tradeoff](bias-variance-overfitting) guide.
---
7. Not Using Cross-Validation
What it is: Relying on a single train/test split for evaluation and hyperparameter tuning.
Why it's dangerous: High variance in performance estimates. You might get lucky or unlucky with one split. Tuning on a single split can overfit to that split.
How to detect: Different random seeds give very different metrics. One split says model A wins; another says model B.
How to fix: Use k-fold (or stratified k-fold for classification) for evaluation. Use nested cross-validation when tuning and evaluating. Report mean and standard deviation across folds.
---
8. Ignoring Baseline Models
What it is: Skipping simple baselines (mean, median, rule-based, logistic regression) and jumping to complex models.
Why it's dangerous: Complex models may not beat simple ones. You waste compute and add unnecessary complexity. Baselines set a performance floor and sanity check.
How to detect: You never compared to a naive baseline. You're not sure if your model is actually useful.
How to fix: Always train at least one baseline: predict the mean (regression), predict majority class (classification), or a simple rule. Ensure your model beats it before investing in complexity.
---
9. Hyperparameter Defaults
What it is: Using default hyperparameters without any tuning, assuming they work for your data.
Why it's dangerous: Defaults are generic. Your dataset may need different regularization, depth, or learning rate. Leaving 10–20% performance on the table is common.
How to detect: You haven't tried any hyperparameter search. Other practitioners report better results with tuned models.
How to fix: Use grid search, random search, or Bayesian optimization with cross-validation. Start with a few key hyperparameters (e.g., learningrate, maxdepth, n_estimators). See the [Hyperparameter Tuning](hyperparameter-tuning) guide.
---
EVALUATION Pitfalls
10. Evaluating on Training Data
What it is: Reporting accuracy or error on the same data used to train the model.
Why it's dangerous: Training metrics are optimistically biased. Overfit models look great on training data and terrible elsewhere.
How to detect: You only have "training accuracy" or "training loss" in your report. No validation or test set metrics.
How to fix: Always hold out a validation set for tuning and a test set for final evaluation. Or use cross-validation. Never report training performance as the final metric.
---
11. Accuracy on Imbalanced Data
What it is: Using accuracy as the primary metric when classes are highly imbalanced (e.g., 99% negative, 1% positive).
Why it's dangerous: A model that always predicts the majority class gets 99% accuracy but catches zero positives. Misleading and dangerous for applications like fraud or disease detection.
How to detect: High accuracy with very few positive predictions. Confusion matrix shows many false negatives.
How to fix: Use F1, AUC-PR, recall, precision, or balanced accuracy. Always inspect the confusion matrix. See the [Imbalanced Data](imbalanced-data-handling) guide.
---
12. Not Checking Residuals for Regression
What it is: Only looking at RMSE or R² without examining residual plots (predicted vs actual, residuals vs features).
Why it's dangerous: Heteroscedasticity, nonlinearity, or outliers can make RMSE/R² misleading. The model may be biased in certain regions.
How to detect: You haven't plotted residuals. Residuals show patterns (e.g., funnel shape, curves) instead of random scatter.
How to fix: Plot residuals vs predicted, vs key features. Check for patterns. Consider transformations, different models, or robust methods if residuals are problematic.
---
13. Ignoring Feature Importance
What it is: Not understanding which features drive predictions — deploying a black box without interpretability.
Why it's dangerous: Spurious or leaking features may dominate. You can't explain or debug. Regulatory and trust issues.
How to detect: You can't answer "why did the model predict X?" You haven't run feature importance or SHAP.
How to fix: Use tree-based feature importance, SHAP, or LIME. Remove or downweight suspicious features. Document key drivers for stakeholders.
---
DEPLOYMENT Pitfalls
14. Training/Serving Skew
What it is: The data or environment at prediction time differs from training time. Features are computed differently, scales change, or preprocessing is inconsistent.
Why it's dangerous: Model receives inputs it wasn't trained on. Predictions become unreliable or crash.
How to detect: Production errors, strange predictions, or sudden performance drops. Log inputs and compare to training distribution.
How to fix: Use the same preprocessing pipeline in training and serving. Version and test preprocessing code. Monitor input distributions (data validation, schema checks). Reuse fitted scalers/encoders from training.
---
15. Model Drift and No Monitoring
What it is: Data distribution or relationships change over time (concept drift), but the model is never retrained or monitored.
Why it's dangerous: Model becomes stale. Performance degrades silently. Business decisions based on outdated predictions.
How to detect: Production metrics decline over time. A/B tests show new data performs worse. No monitoring means you discover drift too late.
How to fix: Set up monitoring: prediction distribution, feature distributions, performance metrics (if labels are available). Define retraining triggers (e.g., monthly, or when drift exceeds a threshold). Have a retraining pipeline ready.
---
Quick Reference Checklist
Before deployment, verify:
| Category | Checklist Item |
|---|---|
| Data | Split before preprocessing? No target leakage? EDA done? Data quality checked? |
| Model | Right metric for the problem? Baseline compared? Cross-validation used? Hyperparameters tuned? |
| Evaluation | Evaluated on hold-out or CV, not training? Right metric for imbalanced data? Residuals checked (regression)? Feature importance reviewed? |
| Deployment | Same preprocessing in train and serve? Monitoring planned? Retraining strategy defined? |
What's Next?
- [ML Overview](ml-overview) — Full ML workflow and best practices
- [Cross-Validation Guide](cross-validation-guide) — Reliable evaluation
- [Model Evaluation Metrics](model-evaluation-metrics) — Choose the right metrics
- [Bias-Variance Tradeoff](bias-variance-overfitting) — Prevent overfitting
Related Articles
Machine Learning Overview: Workflow and Getting Started
A beginner-friendly recap of ML, classification vs regression vs clustering, the ML workflow (select, configure, train, evaluate, predict), and a 5-minute quick-start guide.
Cross-Validation: Reliable Model Evaluation Techniques
Learn how to evaluate ML models reliably using k-fold, stratified, leave-one-out, and time series cross-validation to avoid overfitting and get honest performance estimates.
Model Evaluation Metrics: Accuracy, Precision, Recall, F1, AUC, RMSE, and More
Understand all major ML evaluation metrics for classification and regression, learn when to use each one, and avoid common metric selection mistakes.
Bias-Variance Tradeoff: Understanding Overfitting and Underfitting
Master the bias-variance tradeoff, understand what causes overfitting and underfitting, learn how to detect them with learning curves, and apply regularization (L1/L2), early stopping, and cross-validation to build better models.
Was this helpful?