Customer Segmentation in Python: RFM Scores and k-Means Clustering

<p>WagWell Pet Supplies, a Bengaluru online pet store, has ₹6 lakh to spend on bringing customers back this year. The founder wants a 20%-off coupon for everyone. Nisha Rao, the growth lead, wants to know who the customers are first: who buys often, who has gone quiet, and who was never going to come back.</p><p>Across five lessons you build that answer in Python on your own copy of two years of raw order lines. You clean the export (duplicate lines, cancelled and returned-to-origin orders, lines that are not orders, quantities), build the RFM table with a fixed analysis date, score recency, frequency and monetary by quintile, and name six segments with first-match-wins rules. Then you let the data speak: log-transform and standardise the features, choose k with an elbow chart and the silhouette score, fit k-means, and describe each cluster in days, orders and rupees.</p><p>In every lesson you build the step yourself first, then give the same job to your AI (ChatGPT, Claude, Copilot or Gemini) and learn exactly where it goes wrong: counting lines as orders, the tutorial's "latest date plus one day", recency scored backwards, rules that overwrite each other, k-means on raw rupees, a profile in z-units. In the capstone your AI writes the whole segmentation from one brief, and you prove every number before the budget follows it.</p><p>Bartman runs your script on its own servers against your data and checks the files it writes, customer by customer, so every check is about your real output, not a screenshot.</p>

Tools: Python, pandas, scikit-learn, k-Means Clustering, RFM Analysis, Customer Segmentation, matplotlib, AI Assistants for Python