ML toolkit for time-series sales prediction with feature engineering, validation, and hyperparameter optimization
Project description
Predict Future Sales (Kaggle) — end-to-end ML pipeline
This repository is a pet-project for Kaggle “Predict Future Sales” with a reproducible ML workflow:
- DVC: dataset versioning + reproducible ETL
- Feature engineering: monthly aggregates + lags / rolling means (leakage-safe)
- Models: LightGBM / XGBoost (+ configs / tuning)
- MLflow: experiment tracking + artifacts (SHAP / error analysis)
- Airflow: orchestration demo via
DockerOperator
Project structure
data/raw/: raw CSVs (tracked via DVC.dvcfiles)data/processed/: processed parquet produced by ETL/FEnotebooks/: EDA/DQC/ETL notebooks (+ exported.py)scripts/: training / validation / models / utilitiessubmissions/: Kaggle submission CSVsmlflow/: local MLflow store + artifactsairflow/dags/: DAGpredict_sales_pipeline(orchestration demo)
Quickstart (local)
Requirements
- Python 3.11
- Docker (Docker Desktop)
uv(recommended) orpipdvc(only if you need to pull raw data from a DVC remote)
Option A: install from PyPI
If you only want the Python package (code), install it from PyPI:
- Package page: predict-sales-ml on PyPI
pip install predict-sales-ml
Notes:
- This installs the library, but does not include project files like
compose.yaml,airflow/, or the DVC-tracked datasets. - For Airflow / DVC / end-to-end runs, use Option B (install from source).
Option B: install from source (recommended for the full project)
1) Environment variables
Copy examples and adjust values:
cp .env.example .env
cp airflow.env.example airflow.env
MLFLOW_TRACKING_URI/MLFLOW_EXPERIMENT_NAMEare used byscripts/and by the Airflow DAG.HOST_PROJECT_ROOTmust be an absolute host path to this repo root (required for AirflowDockerOperatorbind-mounts).
2) Install dependencies
Using uv:
uv sync --frozen
Or using pip:
python -m venv .venv
source .venv/bin/activate
pip install -e .
3) Data (DVC)
If raw data is missing, pull it:
dvc pull
Reproduce ETL/feature engineering:
dvc repro
dvc.yamlcontains stageprocess_data, which produces parquet files indata/processed/.
MLflow (local tracking server)
Start MLflow UI via Docker Compose:
docker compose up -d mlflow
MLflow UI will be available at http://localhost:5050 (see compose.yaml).
Model training (CLI)
The main entrypoint for training a single model is scripts/train_single.py.
Train LightGBM and create a submission:
python scripts/train_single.py --model lightgbm
For quick / low-RAM demo runs (e.g., in Airflow), you can point to a smaller parquet and override time splits:
python scripts/train_single.py \
--model lightgbm \
--run-name demo_lightgbm \
--train-encoded tmp/train_small.parquet \
--test-encoded data/processed/test_enriched_encoded.parquet \
--train-start 31 --train-end 31 \
--val-start 32 --val-end 32 \
--test-month 33 --production-month 34 \
--submission-filename demo_submission.csv \
--no-timestamp --no-score
Outputs:
- MLflow: metrics + model + explainability artifacts (if
shapis installed) submissions/: a submission CSV file
Airflow (orchestration demo)
Airflow is started via docker compose with the airflow profile.
- Start services:
docker compose --profile airflow up -d airflow-postgres airflow-init airflow-webserver airflow-scheduler
-
Open UI:
http://localhost:8080 -
DAG:
predict_sales_pipeline
Important:
- The DAG uses
DockerOperatorand needs Docker socket access (see volume/var/run/docker.sock). - For bind-mounts to work, set
HOST_PROJECT_ROOTinairflow.env.
What the pipeline does
- ETL/FE:
dvc repro→notebooks/03_ETL.pyproducessales_monthly_with_features(_encoded).parquet - Validation:
TimeSeriesValidator+BaselineFeatureExtractor(uses the (N \leftarrow N-1) pattern to avoid leakage) - Training:
scripts/train_single.py→TrainingPipeline - Explainability: SHAP + error analysis (see
scripts/explainability.py, artifacts inmlflow/artifacts/)
Troubleshooting
- If training inside Docker cannot reach MLflow:
- containers typically need
MLFLOW_TRACKING_URI=http://host.docker.internal:5050 - local host runs typically use
MLFLOW_TRACKING_URI=http://localhost:5050
- containers typically need
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file predict_sales_ml-1.0.0.tar.gz.
File metadata
- Download URL: predict_sales_ml-1.0.0.tar.gz
- Upload date:
- Size: 558.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61664727e8daf5c4b72c155afb908cee69965c4d207424fef75f93cea7cb48ec
|
|
| MD5 |
5c1057eb5159ef073645e823f7e54861
|
|
| BLAKE2b-256 |
5bc8b656caee9e1fdfc5c0679657b20a409ec0563192ccecb45d18c4b0eac76d
|
File details
Details for the file predict_sales_ml-1.0.0-py3-none-any.whl.
File metadata
- Download URL: predict_sales_ml-1.0.0-py3-none-any.whl
- Upload date:
- Size: 75.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddfbf04cc59cfa809f21fc9e17857c203358082186c0b38b222a946a7bb8eac2
|
|
| MD5 |
533757caca859ef49b883dda7cba1592
|
|
| BLAKE2b-256 |
a1f5ed080a5d31699252932bda00d05ed53c9817b6a9d69a17fc33f5511716f5
|