I implemented Part B of the Instamart Copilot, an end‑to‑end pipeline that computes RFM‑based customer segmentation with K‑Means and builds a binary lapse‑prediction model for churn risk. All code resides in src/part_b.py and results are written under the outputs/ folder. I launch the pipeline with the command shown in the first quote below.
Features are computed using completed orders only, evaluated at the fixed reference snapshot 2025-10-01 00:00:00.
The RFM step processes 1,175 customers with at least one completed order.
K‑Means clustering was evaluated for K = 2 … 8; K = 4 achieved the highest silhouette score of 0.5255 and an inertia of 743.07.
The dynamic “Premium” segment contains 138 customers (11.7 % of the population) with a mean monetary spend of INR 7,129.70.
The selected RandomForest model (max_depth=3, min_samples_leaf=20) achieved a held‑out test F1 score of 0.6595 for the lapsed class, surpassing the business target of 0.55.
The trained model was persisted to outputs/lapse_model.joblib and re‑loaded without any prediction drift.
An illustrative retention priority list of the top‑10 highest‑risk Premium customers was saved as outputs/retention_list.csv.

