Turn three customer questions into segments
Ask when, how often, and how much a customer bought before learning the RFM acronym and label rules.
Question for this chapter
Which three questions help choose a customer's next action?
Why this matters now
The questions are easier to understand than the acronym:
- How recently did they buy? — days since the latest order
- How frequently did they buy? — distinct order count
- How much did they spend? — total purchase value
Their initials form Recency, Frequency, and Monetary value: RFM.
Try it
Open the customer_segmentation pipeline under analytics and select Run. It runs two steps:
join_datasets— inner-join cleaned orders with customers oncustomer_idrfm_segmentation— aggregate the last order, order count, and spend, then assign a label
The current code uses one day after the latest order in the data as its reference date.
| Condition | Segment | Plain-language reading |
|---|---|---|
| Within 30 days, 5 or more orders | champion | Bought often and recently |
| Within 30 days, 2–4 orders | loyal | Repeated recent purchases |
| More than 30 days, 2 or more orders | at_risk | Bought repeatedly, then went quiet |
| Everything else | new | Usually a one-time customer |
Spend remains in total_spend and avg_order_value as campaign context, but the current label branch
itself uses recency and order count.
Success looks like this
customer_analytics contains 22 rows with total_orders, total_spend, avg_order_value,
last_order_date, and segment populated.
Next decision
You understand the rules. Next, count how the 22 customers actually distribute across the four labels and identify the group that does not exist.