Skip to main content

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 .dvc files)
  • data/processed/: processed parquet produced by ETL/FE
  • notebooks/: EDA/DQC/ETL notebooks (+ exported .py)
  • scripts/: training / validation / models / utilities
  • submissions/: Kaggle submission CSVs
  • mlflow/: local MLflow store + artifacts
  • airflow/dags/: DAG predict_sales_pipeline (orchestration demo)

Quickstart (local)

Requirements

  • Python 3.11
  • Docker (Docker Desktop)
  • uv (recommended) or pip
  • dvc (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:

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_NAME are used by scripts/ and by the Airflow DAG.
  • HOST_PROJECT_ROOT must be an absolute host path to this repo root (required for Airflow DockerOperator bind-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.yaml contains stage process_data, which produces parquet files in data/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 shap is installed)
  • submissions/: a submission CSV file

Airflow (orchestration demo)

Airflow is started via docker compose with the airflow profile.

  1. Start services:
docker compose --profile airflow up -d airflow-postgres airflow-init airflow-webserver airflow-scheduler
  1. Open UI: http://localhost:8080

  2. DAG: predict_sales_pipeline

Important:

  • The DAG uses DockerOperator and needs Docker socket access (see volume /var/run/docker.sock).
  • For bind-mounts to work, set HOST_PROJECT_ROOT in airflow.env.

What the pipeline does

  • ETL/FE: dvc repronotebooks/03_ETL.py produces sales_monthly_with_features(_encoded).parquet
  • Validation: TimeSeriesValidator + BaselineFeatureExtractor (uses the (N \leftarrow N-1) pattern to avoid leakage)
  • Training: scripts/train_single.pyTrainingPipeline
  • Explainability: SHAP + error analysis (see scripts/explainability.py, artifacts in mlflow/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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

predict_sales_ml-1.0.0.tar.gz (558.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

predict_sales_ml-1.0.0-py3-none-any.whl (75.5 kB view details)

Uploaded Python 3

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

Hashes for predict_sales_ml-1.0.0.tar.gz
Algorithm Hash digest
SHA256 61664727e8daf5c4b72c155afb908cee69965c4d207424fef75f93cea7cb48ec
MD5 5c1057eb5159ef073645e823f7e54861
BLAKE2b-256 5bc8b656caee9e1fdfc5c0679657b20a409ec0563192ccecb45d18c4b0eac76d

See more details on using hashes here.

File details

Details for the file predict_sales_ml-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for predict_sales_ml-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddfbf04cc59cfa809f21fc9e17857c203358082186c0b38b222a946a7bb8eac2
MD5 533757caca859ef49b883dda7cba1592
BLAKE2b-256 a1f5ed080a5d31699252932bda00d05ed53c9817b6a9d69a17fc33f5511716f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page