Machine Learning Best Practices
A checklist of rules for building reproducible, leak-free classical ML models. Walk it before every training run and during code review.
Search across all documentation pages
A checklist of rules for building reproducible, leak-free classical ML models. Walk it before every training run and during code review.
GroupKFold when multiple rows share a user, patient, or session ID.OneHotEncoder(handle_unknown="ignore") or native categorical support in boosting libraries.StandardScaler or distance-based models.X[expected_columns] before predict to prevent silent misalignment.random_state=42 on splits, models, and search for reproducible experiments.joblib.dump(pipe, ...) - not just the classifier step.f1, roc_auc, or neg_mean_absolute_error - not default accuracy.pipe.predict(sample) returns expected shape and dtype.Pipeline and proper split order.random_state, pinned deps, and experiment tracking.imblearn.pipeline.Pipeline after the train split.project/
data/ # raw and processed (gitignored or DVC)
src/train.py # training script
src/predict.py # inference entrypoint
models/ # serialized pipelines
tests/ # inference smoke testsdef test_pipeline_predicts(sample_row):
pred = pipe.predict(sample_row)
assert pred.shape == (1,)Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 16, 2026