Lesson 3: Customer Segmentation — RFM Analysis, Behavioral Segmentation, and Clustering

Why Segmentation Matters

Imagine a company with 100,000 customers.

Should every customer receive the same promotion?

Probably not.

Consider:

  • One customer spends $10,000 every year.
  • Another spends $20 once and never returns.

Treating them identically wastes money.

Segmentation helps businesses answer:

  • Who are our best customers?
  • Who is likely to churn?
  • Who should receive promotions?
  • Who should receive premium service?
  • Which customers should we ignore?

Customer segmentation is one of the most common applications of data science.


Learning Objectives

By the end of this lesson, you should be able to:

  • Understand customer segmentation
  • Perform RFM analysis
  • Build customer scores
  • Understand behavioral segmentation
  • Understand clustering methods
  • Apply segmentation to healthcare
  • Apply segmentation to supply chains
  • Build customer groups using machine learning

What Is Segmentation?

Segmentation means dividing customers into groups that behave similarly.

Instead of:

$$100000\ customers$$

we create smaller groups.

Example:

SegmentDescription
VIPHigh value
LoyalFrequent buyers
At RiskMay leave soon
NewRecently acquired
DormantInactive

This allows targeted decision-making.


Why Segmentation Creates Value

Suppose a company has:

$$10000\ customers$$

and sends a $20 coupon to everyone.

Cost:

$$10000\times20=200000$$

Now suppose segmentation identifies:

$$1000$$

high-risk customers.

Coupon cost:

$$1000\times20=20000$$

Same retention effect.

Much lower cost.


The RFM Framework

RFM is one of the oldest and most effective segmentation techniques.

RFM stands for:

  • Recency
  • Frequency
  • Monetary Value

Recency

Recency measures how recently a customer purchased.

Formula:

$$Recency=Current\ Date-Last\ Purchase\ Date$$

Example:

Customer A purchased:

5 days ago

Customer B purchased:

180 days ago

Customer A is generally more valuable.


Why Recency Matters

Most businesses observe:

The more recently a customer purchased, the more likely they are to purchase again.

A customer who purchased yesterday behaves differently from one who has been inactive for a year.


Frequency

Frequency measures how often customers purchase.

Formula:

$$Frequency=Number\ of\ Purchases$$

Example:

Customer A:

$$Frequency=25$$

Customer B:

$$Frequency=2$$

Customer A is typically more engaged.


Monetary Value

Monetary value measures spending.

Formula:

$$Monetary=\sum Purchases$$

Example:

Customer A:

$$Monetary=10000$$

Customer B:

$$Monetary=150$$

Customer A contributes much more revenue.


Example RFM Table

CustomerRecencyFrequencyMonetary
A52010000
B30124000
C1203300
D300150

Interpretation:

  • A is likely VIP
  • B is loyal
  • C is declining
  • D is dormant

Creating RFM Scores

A common approach is assigning scores from 1–5.

Example:

Recency:

Days Since PurchaseScore
0–305
31–604
61–1203
121–1802
>1801

Frequency:

PurchasesScore
Highest 20%5
Next 20%4
Next 20%3
Next 20%2
Lowest 20%1

Monetary is scored similarly.


Combined RFM Score

Suppose:

$$R=5$$

$$F=4$$

$$M=5$$

Combined score:

$$RFM=545$$

or

$$Score=R+F+M=14$$

Higher values indicate more valuable customers.


Typical RFM Segments

SegmentExample
Champions555
Loyal Customers544
Potential Loyalists454
At Risk211
Lost Customers111

Behavioral Segmentation

RFM uses transaction data.

Behavioral segmentation uses customer actions.

Examples:

  • Website visits
  • App usage
  • Search history
  • Product views
  • Support requests

These often predict future purchases better than historical sales.


Example Behavioral Features

Suppose we track:

  • Website visits
  • Average session length
  • Pages viewed
  • Purchases

Customer A:

MetricValue
Visits50
Session Length12 min
Purchases8

Customer B:

MetricValue
Visits2
Session Length30 sec
Purchases0

Customer A is much more engaged.


Segmentation Using Machine Learning

Instead of manually creating groups, we can let algorithms discover them.

This is called unsupervised learning.

The most common method is:

K-Means Clustering


Intuition Behind K-Means

Suppose each customer has:

$$x=(Recency,Frequency,Monetary)$$

Customers with similar values are grouped together.

The algorithm finds cluster centers:

$$\mu_1,\mu_2,\ldots,\mu_K$$

Each customer is assigned to the nearest center.


K-Means Objective Function

The algorithm minimizes:

$$\sum_{i=1}^{n}\sum_{k=1}^{K}I(z_i=k)|x_i-\mu_k|^2$$

Meaning:

Find groups where customers are as similar as possible.


Example Clusters

Suppose K-Means finds:

Cluster 1

High frequency

High spending

Recent purchases

VIP customers


Cluster 2

Moderate spending

Moderate activity

Regular customers


Cluster 3

Low spending

Long inactivity

Churn risk


Healthcare Example

Suppose a hospital segments patients.

Variables:

  • Number of appointments
  • Medication adherence
  • Chronic disease score

Clusters may reveal:

Segment 1

Highly engaged patients

Segment 2

Moderately engaged patients

Segment 3

High-risk patients needing intervention


Supply Chain Example

Suppose a wholesaler segments retailers.

Variables:

  • Annual sales
  • Inventory turnover
  • Order frequency

Cluster 1:

High-performing retailers

Cluster 2:

Stable retailers

Cluster 3:

Declining retailers

This is very similar to the retailer segmentation work you already perform.


Segment Migration

Customers are not static.

Example:

January:

$$Segment=Champion$$

June:

$$Segment=At\ Risk$$

Data scientists often track movement between segments.

This is called segment migration.


Python Example: RFM Scoring

import pandas as pd
rfm = pd.DataFrame({
"Customer":["A","B","C","D"],
"Recency":[5,30,120,300],
"Frequency":[20,12,3,1],
"Monetary":[10000,4000,300,50]
})
print(rfm)

Output:

  Customer  Recency  Frequency  Monetary
0        A        5         20     10000
1        B       30         12      4000
2        C      120          3       300
3        D      300          1        50


Python Example: K-Means Clustering

from sklearn.cluster import KMeans
import pandas as pd
X = pd.DataFrame({
"Recency":[5,30,120,300],
"Frequency":[20,12,3,1],
"Monetary":[10000,4000,300,50]
})
model = KMeans(n_clusters=3, random_state=42)
clusters = model.fit_predict(X)
print(clusters)

Complete Business Example

Suppose a retailer has:

$$50000$$

customers.

Segmentation reveals:

SegmentCustomers
VIP5,000
Loyal15,000
Regular20,000
At Risk7,000
Lost3,000

Marketing budget:

$$500000$$

Instead of distributing promotions equally, the company can focus on:

  • Retaining VIPs
  • Re-engaging At Risk customers
  • Ignoring Lost customers

This dramatically improves ROI.


Key Takeaways

The core concepts introduced in this lesson are:

$$Recency=Current\ Date-Last\ Purchase\ Date$$

$$Frequency=Number\ of\ Purchases$$

$$Monetary=\sum Purchases$$

$$RFM=(Recency,Frequency,Monetary)$$

Segmentation helps businesses:

  • Increase retention
  • Improve marketing efficiency
  • Reduce churn
  • Increase revenue
  • Personalize customer experiences

The most common approaches are:

  1. RFM Analysis
  2. Behavioral Segmentation
  3. K-Means Clustering
  4. Customer Journey Analysis

These techniques form the foundation of customer analytics, retail analytics, healthcare engagement analytics, and supply chain customer management.


Exercises

  1. Calculate RFM values for five customers using hypothetical purchase histories.
  2. Design five customer segments for a jewelry retailer.
  3. Design five customer segments for a hospital.
  4. Explain why recency is often a stronger predictor than monetary value.
  5. Fit a K-Means model with:

$$K=3$$

and then:

$$K=5$$

Compare the resulting segments.


References

  1. Fader, Peter S. Customer Centricity. Wharton Digital Press.
  2. Gupta, Sunil & Lehmann, Donald. Managing Customers as Investments.
  3. James, Gareth, Witten, Daniela, Hastie, Trevor, Tibshirani, Robert. An Introduction to Statistical Learning.
  4. Hastie, Trevor, Tibshirani, Robert, Friedman, Jerome. The Elements of Statistical Learning.
  5. Han, Jiawei, Kamber, Micheline, Pei, Jian. Data Mining: Concepts and Techniques.

Next Lesson

Lesson 4: Customer Lifetime Value Modeling — From Simple LTV to Probabilistic Models (BG/NBD and Gamma-Gamma Models), where we move from descriptive segmentation into predictive customer valuation.

Leave a Reply

Discover more from nerd-ish

Subscribe now to keep reading and get access to the full archive.

Continue reading