Skip to content
  • Common Pitfalls · Machine Learning

Common Pitfalls

LearnViaNotes @learnvianotes· 3 min read

Most ML failures are process bugs, not algorithm choices. This checklist collects the classic ones with their symptoms and fixes.

PitfallSymptomFix
Data leakageOffline scores too good; collapse in productionSplit first, Pipeline, check feature availability at prediction time (see Data Leakage)
Duplicates / same entity across splitsNear-perfect validation scoresDeduplicate; group splits
Random split of time-ordered dataProduction worse than validationTime-based split / TimeSeriesSplit
Accuracy on imbalanced dataHigh accuracy, useless modelPR-AUC, recall/precision, cost; baseline comparison
No baselineCan't tell if the model adds valueDummy model + existing rule
Tuning on the test setTest score optimistic; disappointment laterValidation/CV for all choices; nested CV
Overfitting the validation setMany experiments, tiny “wins” that don't replicateLarger validation set, repeated CV, report variance
Preprocessing fitted on all dataSlightly-to-very optimistic scoresFit scalers/encoders/imputers/selectors inside CV
Training–serving skewSame input, different prediction online vs offlineOne shared feature pipeline; log production features and compare
Distribution shiftSlow decay after launchMonitor inputs/outputs, retrain (see Deployment, Monitoring & MLOps)
Spurious correlations (shortcut learning)Great on validation, fails on new sourcesError analysis, explainability, test on data from other sources/times
Selection / sampling biasModel fails on groups under-represented in trainingFix collection; slice metrics
Label noisePlateaued accuracy; confident “errors” that are rightAudit labels, agreement metrics, clean the test set
Unscaled features for distance/regularised modelsk-NN/SVM/Lasso behave oddlyScale inside the pipeline
Single run, no uncertaintyImprovements within noiseCV mean ± std, confidence intervals, significance tests
Deep learning on small tabular dataHours of tuning, worse than a forestStart with linear models and gradient boosting

Demo: duplicates across the split

Random labels — nothing to learn — but each row appears three times. A random split puts copies of test rows into training, and a 1-nearest-neighbour model “recognises” them:

Python
import numpy as np
from sklearn.model_selection import GroupShuffleSplit, train_test_split
from sklearn.neighbors import KNeighborsClassifier

rng = np.random.default_rng(0)
X0 = rng.normal(size=(300, 5))
y0 = rng.integers(0, 2, size=300)                  # random labels
X, y = np.repeat(X0, 3, axis=0), np.repeat(y0, 3)  # every row duplicated 3×
row_id = np.repeat(np.arange(300), 3)

X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=0)
print(round(KNeighborsClassifier(1).fit(X_tr, y_tr).score(X_te, y_te), 2))   # 0.97 ← "learned" noise

tr, te = next(GroupShuffleSplit(test_size=0.3, random_state=0).split(X, y, groups=row_id))
print(round(KNeighborsClassifier(1).fit(X[tr], y[tr]).score(X[te], y[te]), 2))   # 0.53 ← honest: chance level

Before you trust a result

  1. Is there a baseline, and does the model clearly beat it?

  2. Was the split done first, and by time/group where needed?

  3. Is every feature available at prediction time?

  4. Is all preprocessing inside the pipeline?

  5. Is the metric the one the business cares about, at the threshold that will be used?

  6. Is the improvement larger than the run-to-run variance?

  7. Has the test set been used only once?

What are the most common mistakes in ML projects?

A model does great offline but poorly in production. What could be wrong?

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report