Survival prediction with feature store and drift monitoring
Predicts Titanic passenger survival from Redis-stored features, fed by Airflow ETL and monitored for drift.
What it does
An Astro Airflow DAG lists and downloads the Titanic CSV from a GCS bucket and loads it into PostgreSQL. A psycopg2 ingestion step reads the table, processing balances classes with SMOTE and stores per-passenger features in Redis, and a Random Forest is tuned with RandomizedSearchCV on features read back from the store. The Flask app checks each request for drift with Alibi Detect's KS test and exposes prediction and drift counters to Prometheus and Grafana.
What was built
- 01
Airflow DAG chains a GCS listing, GCS-to-local download and a pandas to_sql load into a titanic Postgres table.
- 02
Processing applies SMOTE and writes each passenger's features to Redis under entity:<id>:features keys.
- 03
Training fetches features from Redis by entity ID and tunes a Random Forest with RandomizedSearchCV.
- 04
Each Flask prediction is checked against reference data with a KSDrift detector at p=0.05; detected drift increments a counter.
- 05
Prometheus scrapes prediction_count and drift_count from the app; Grafana runs beside it in Docker Compose.
The pipeline, layer by layer
Five layers, one pipeline.
L1ETL
- GCS bucket
- Airflow DAG
- PostgreSQL table
L2Features
- SMOTE processing
- Redis feature store
L3Training
- Random Forest search
L4Serving
- Flask prediction app
- KSDrift check
L5Monitoring
- Prometheus
- Grafana