Customer Analytics
Customer Segmentation
Two complementary techniques for understanding your customers — RFM Analysis for behaviour-based scoring, and Cluster Analysis for data-driven grouping. From theory to implementation with real datasets.
Introduction to Segmentation
Before diving into RFM, it helps to understand the broader landscape of how businesses group their audiences.
Market Segmentation
Dividing a broad target market into segments based on demographics, geography, psychographics, or behaviour. The goal: develop customised strategies for each group to maximise marketing effectiveness and resource allocation.
Customer Segmentation
Goes deeper than market segmentation by incorporating past interactions, purchase history, lifetime value, visit frequency, and spending patterns. Uncovers the shared characteristics of your most profitable customer groups.
Segmentation Variables
| Type | Example Variables |
|---|---|
| Demographic | Gender, age, marital status, occupation, income |
| Geographic | City, region, country |
| Psychographic | Interests, values, character & personality traits |
| Behavioural | Purchases, product preference, frequency, amount spent |
| Technographic | Device type, browser, software, websites |
| Needs-based | Financial (discounts), emotional (service feedback), physical |
Why segment?
- Targeted campaigns — Personalised messaging to each segment’s interests
- Better communication — Right channel for the right customer
- Product improvements — Direct view into customer challenges
- Stronger relationships — Every customer feels valued, not generic
- Revenue growth — Informed upselling and cross-selling
- Cost efficiency — Focus spend on responsive segments
What is RFM?
A quantitative method that scores every customer on three behavioural dimensions.
Recency
How recently did the customer purchase? Recent buyers still have the product on their mind and are more likely to buy again.
Frequency
How often do they buy? Frequent purchasers have established a habit and are more likely to return.
Monetary
How much do they spend? High spenders deliver the most revenue and tend to continue spending.
What can you do with RFM?
- Identify high-value customers — Score 555 = VIP. Foster deeper relationships
- Customise marketing — Different strategies per segment
- Improve retention — Score 1XX = at risk. Trigger win-back campaigns
- Reduce costs — Stop sending campaigns to unresponsive customers
The 4-Step RFM Workflow
From raw transactions to actionable customer segments.
Data Collection
Gather transaction-level data with three essentials: Customer ID, Order Date, and Revenue Amount. If pre-aggregated, include last transaction date and total spend per customer.
Build the RFM Table
Aggregate by Customer ID: count orders (Frequency), find most recent order date, and sum revenue (Monetary). Calculate elapsed days since last order relative to your analysis date for Recency.
Assign RFM Scores
Sort each dimension and divide into quintiles (5 equal-sized groups). Assign scores 1–5, where 5 = best. For Recency: lowest elapsed days = 5. For Frequency and Monetary: highest values = 5.
Create Segments
Combine R, F, M scores into a three-digit code (e.g., 555 = best customer, 111 = least engaged). Group codes into meaningful segments with descriptive labels.
Segmentation Strategies
125 possible RFM cells (5×5×5) are too many to act on. Here’s how to reduce them.
25-Segment Matrix
Use only R and F scores as axes, with M as an aggregation metric (mean monetary per cell). Reduces 125 cells to a manageable 5×5 grid. Each cell answers: “How recent and how frequent, with what average spend?”
11-Segment Strategy
A popular industry approach that maps RFM scores into named personas. Each gets a tailored engagement strategy.
The 11 RFM Segments & Engagement Strategies
| Segment | R | F | M | Action |
|---|---|---|---|---|
| Champions | 5 | 4–5 | 4–5 | Reward them; early access to new launches |
| Loyal Customers | 3–4 | 4–5 | 4–5 | Suggest higher-value products; ask for reviews |
| Potential Loyalists | 4–5 | 2–3 | 2–3 | Loyalty programmes; cross-category recommendations |
| New Customers | 4–5 | 1–2 | 1–2 | Smooth onboarding; post-sale support |
| Promising | 3–4 | 1–2 | 1–2 | Brand awareness; free trials |
| Need Attention | 3 | 2–3 | 2–3 | Limited-period offers; personalised recommendations |
| About to Sleep | 2–3 | 1–3 | 1–3 | Reactivation offers; popular products |
| At Risk | 1–2 | 3–4 | 3–4 | Best deals; highest-rated product recommendations |
| Can’t Lose Them | <2 | 4–5 | 4–5 | Listen to feedback; win them back with new products |
| Hibernating | 1–2 | 1–2 | 1–2 | Cross-category offers; personalised outreach |
| Lost | 1 | 1 | 1 | Periodic brand awareness campaigns |
Beyond Basic RFM
Hurdle rates, RFM variations, and combining RFM with clustering.
Hurdle Rate Analysis
Set thresholds for each R, F, M dimension (e.g., purchased within 90 days, 3+ purchases, $500+ spent) and track the percentage of customers clearing each hurdle over time.
- Rates rising? — Business is healthy; customers respond positively
- Rates falling? — High-value customers are defecting; future value is declining
- One hurdle drops? — Pinpoints exactly which behaviour needs attention
RFM Across Industries
- E-commerce — Personalised product recommendations based on purchase recency, frequency, and spend
- Travel & Hospitality — Loyalty programme enhancement by segmenting booking behaviour
- Gaming — In-game purchase optimisation using login frequency and monetisation patterns
- Media & Content — Subscription renewal and engagement strategy based on consumption behaviour
RFD — Duration
Replaces Monetary with Duration for viewership/readership businesses (e.g., Netflix). Measures session length instead of spending.
RFE — Engagement
Replaces Monetary with Engagement — pages per visit, interactions, or similar metrics. Ideal for platforms like TikTok or content sites.
Strengths & Limitations
Strengths
- Simple to understand and implement
- Provides directly actionable segments
- Customisable thresholds per industry
- Identifies high-value customers immediately
- Flexible segmentation granularity
Limitations
- Ignores demographics and preferences
- Static snapshot — doesn’t track changes over time
- Focuses only on monetary transactions
- Assumes R, F, M are independent (often not true)
- Threshold selection is subjective
Introduction to Clustering
An unsupervised learning method that discovers natural patterns in data and groups them into meaningful clusters.
What is Clustering?
Clustering reduces complex datasets into smaller, homogeneous groups. Observations within a cluster are similar to each other but dissimilar to observations in other clusters. No predefined categories — the algorithm discovers the structure.
Clustering vs Classification
Classification assigns data to known categories (supervised). Clustering discovers unknown categories (unsupervised). Classification needs labelled training data; clustering works with unlabelled data.
The Cluster Analysis Process
- Select variables — Choose relevant features; reduce dimensions if too many correlated variables
- Define distance metric — Choose how to measure similarity between data points
- Apply clustering technique — Split observations into clearly different groups
- Determine number of clusters — Use technical and business criteria to find optimal K
- Profile each cluster — Create descriptions based on variable values within each cluster
- Validate — Confirm clusters are meaningful and actionable; iterate if needed
Similarity & Distance Measures
Clustering algorithms need a way to quantify how “close” or “far” data points are.
Euclidean Distance
The default distance measure for K-Means. Calculates the straight-line distance between two points in multi-dimensional space. Example: Australia–Italy distance = 5.39 (similar), Australia–Somalia = 144.40 (very different).
Standardise First
Variables on different scales (e.g., income in thousands vs. age in decades) will distort distance calculations. Always standardise your data before clustering so each variable contributes equally.
Non-Numerical Data
Ordinal data (e.g., Likert scale: Strongly Disagree → Strongly Agree) can use index-based distances. Nominal data (e.g., gender, marital status) generally should not be used for clustering — use them later for profiling instead.
Other Distance Measures
- Manhattan (City-block) — Sum of absolute differences; less sensitive to outliers than Euclidean
- Chebychev — Maximum difference across any single dimension
- Mahalanobis — Accounts for correlations between variables and differences in scale
Hierarchical Clustering
Builds a tree of clusters by progressively merging (or splitting) groups.
Agglomerative (Bottom-Up)
Start with each point as its own cluster. At each step, merge the closest pair. Repeat until a single cluster remains. The most common variant. Results displayed as a dendrogram.
Divisive (Top-Down)
Start with one all-inclusive cluster. Recursively split using a flat algorithm (e.g., K-Means with k=2) until only singletons remain.
Inter-Cluster Distance Methods
- Single Linkage — Distance between the closest points of two clusters
- Complete Linkage — Distance between the farthest points
- Average Linkage — Average distance of all point pairs
- Ward’s Method — Minimises total within-cluster variance on merge
- Centroid — Distance between cluster centres
K-Means Clustering
The most widely used clustering algorithm — simple, fast, and surprisingly effective.
Choose K & Initialise
Specify the number of clusters K. Randomly select K data points as initial centroids (seed points).
Assign Points
Calculate the distance from every data point to each centroid. Assign each point to its nearest centroid, forming K clusters.
Recompute Centroids
For each cluster, calculate the new centroid (mean position of all assigned points).
Repeat Until Stable
Iterate steps 2–3 until no points change clusters, centroids stabilise, or a maximum iteration count is reached.
nstart = 25) and pick the best.
K-Means Variations
- K-Medoids — Uses actual data points (medoids) as cluster centres instead of means; more robust to outliers
- K-Median — Computes median in each dimension using Manhattan distance
- K-Modes — For categorical data; clusters based on matching categories
- K-Prototype — Combines K-Modes and K-Means for mixed numerical/categorical data
Evaluating Cluster Quality
How do you know your clusters are good? Two complementary approaches: technical metrics and business profiling.
Technical Validation
Elbow Method (WSS)
Run K-Means for k=2…10 and plot Within-cluster Sum of Squares. Look for the “elbow” where adding more clusters gives diminishing returns.
Silhouette Coefficient
Measures both cohesion (intra-cluster) and separation (inter-cluster). Ranges from −1 (worst) to +1 (best). Score > 0.3 is generally acceptable.
- Cluster sizes — One dominant cluster may need further splitting; very small clusters may be outliers
- Boxplots — Show variable distributions per cluster; look for significant differences across variables
Business Validation — Cluster Profiling
Technical metrics alone aren’t enough. Work with domain experts to answer four questions:
- Distinguishing characteristics? — Look for extreme highs and lows in each cluster
- Explainable? — Can each cluster be described in business terms?
- Labelable? — Can you intuitively assign names? (e.g., “Advanced”, “Moderate”, “Developing”)
- Actionable? — Can each cluster drive a specific marketing, sales, or service action?
Strengths & Limitations
Strengths
- Enables personalised marketing per segment
- Data-driven — removes subjective bias
- Improves customer satisfaction
- Optimises resource allocation
- Generates deep behavioural insights
Limitations
- Assumes homogeneity within clusters
- Choosing optimal K is non-trivial
- Interpretation can be subjective
- Real customers may span multiple segments
- Sensitive to outliers and noise
Applications Across Industries
- Sales & Marketing — Discover customer groups and develop targeted campaigns
- Fraud Detection — Identify uncharacteristic transaction behaviour
- Healthcare — Group patients by risk profile for predictive care
- Insurance — Identify policyholder groups with high claim costs
AI Agent for Segmentation, Prediction and Personalization
A hands-on CrewAI workshop that turns everything in this module — segmentation, clustering, regression — into a working multi-agent AI product.
Scenario
A bank wants to help customers understand the environmental impact of their spending. But the bank must answer three questions:
- Identification — How do we identify sustainability behaviours across millions of customers?
- Estimation — How do we estimate carbon impact from spending?
- Personalisation — How do we personalise insights for each customer?
Insight → Foresight → Action
The same three-step pattern used across this course's agents, applied here to sustainable spending.
Insight — Segment customers
K-Means clustering on five spend categories (restaurants, shopping, travel, groceries, entertainment) plus total spend and estimated CO2e. Optimal k is chosen automatically via the highest Silhouette Score — the same validation technique covered in the Cluster Analysis tab.
Foresight — Predict carbon impact
An OLS regression predicts estimated_co2e from the five spend categories (R² = 0.896). Coefficients reveal which categories drive emissions the most — travel has by far the largest per-dollar impact.
Action — Simulate & recommend
A what-if simulator tests scenarios (e.g. “reduce travel 20%”, “reduce travel/restaurants/shopping 15%”) against the regression model, then a CrewAI crew turns the best scenario into a personalised, financially-framed email.
Meet the CrewAI Crew
Three agents, each with a narrow role, working sequentially so the final output stays grounded in the actual model outputs rather than a generic LLM guess.
Sustainability Insight Analyst
Goal: Explain customer sustainability segments in business language and flag which clusters carry the highest carbon impact.
Carbon Impact Forecast Specialist
Goal: Interpret the regression output — model fit, statistical significance, and the top emissions drivers — for a non-technical reader.
Sustainable Lifestyle Advisor
Goal: Turn the winning what-if scenario into a short, supportive email with three practical, re-allocation-based recommendations.
What-If Scenario Table
Sample output for one customer in the demo dataset — this is the exact table the Action agent reasons over.
Customer #50 · Cluster 0 · Baseline predicted CO2e: 689.61
| Scenario | Predicted CO2e | Reduction | Reduction % |
|---|---|---|---|
| Baseline (no change) | 689.61 | — | — |
| Reduce travel 20% | 677.85 | 11.77 | 1.71% |
| Reduce restaurants 20% | 677.12 | 12.49 | 1.81% |
| Reduce shopping 20% | 683.76 | 5.86 | 0.85% |
| Reduce travel/restaurants/shopping 15% | 667.03 | 22.59 | 3.28% |
The best scenario spreads a smaller cut across three categories rather than a deep cut in one — exactly the kind of re-allocation insight the Action agent is asked to explain.
Try It Yourself
Run the full notebook in Google Colab — clustering, regression, what-if simulation, and the live CrewAI crew.
Before you run it
- Dataset — Upload a
sustainable_customer_personas.csvwith columns for restaurant/shopping/travel/groceries/entertainment spend and anestimated_co2etarget. - API key — You'll need an OpenAI API key to run the CrewAI agents (set as
OPENAI_API_KEY).
Extend the activity
- Change the
chosen_customer_idand re-run — how does the recommended scenario shift across clusters? - Edit the Action agent's
backstoryand email requirements — try a more playful tone, or add a loyalty-points incentive. - Add a fourth what-if scenario (e.g. reduce groceries or entertainment) and see if it ever beats the current best.
Interested in this module?
Part of the Customer Analytics programme. Get in touch for details.