End-to-end pipeline for periodic retraining of a gradient boosting model with:
- data drift detection (Evidently)
- experiment tracking and model registry (MLflow)
- orchestration (Prefect 2)
- PostgreSQL storage for training data and incoming data
src/consumer: readsdata/inference.zipand writes raw rows tonew_datasrc/data_processing: feature engineering + validation, moves rows intotrainsrc/retraining: Prefect flow that detects drift, trains XGBoost, logs to MLflow, and promotes the best modelsrc/database: DB helpers and schemamodels/: baseline model artifact
- Create
.env(or use defaults):
PG_DB=mlops
PG_USER=mlops
PG_PASSWORD=mlops
EXPERIMENT_NAME=xgb-retrain
MODEL_NAME=xgb-model
- Build and start core services:
docker compose up --build db mlflow prefect
- Ingest raw data to
new_data:
docker compose up --build consumer
- Log the first model into MLflow:
docker compose run --rm bootstrap_mlflow
- Run the retraining flow once:
docker compose run --rm retraining
- Prefect:
http://localhost:4200 - MLflow:
http://localhost:5001
Required for DB and tracking:
PG_DB,PG_USER,PG_PASSWORD,PG_HOST,PG_PORTEXPERIMENT_NAME,MODEL_NAMEMLFLOW_TRACKING_URI(default in compose:http://mlflow:5001)PREFECT_API_URL(default in compose:http://prefect:4200/api)MODEL_PATH(optional, overridesmodels/model.ubj)
consumerreadsdata/inference.zipfrom the repo and writes tonew_data.- Feature engineering also validates rows before moving them to
train. - MLflow uses a local SQLite backend inside the container volume.
- If MLflow returns
Invalid Host header, ensureMLFLOW_SERVER_ALLOWED_HOSTSis set indocker-compose.yml. - If Prefect errors with client/server version mismatch, rebuild
retraining(it pins Prefect 2.20.18).
