Recency, frequency, monetary (RFM) segmentation

Customer Segmentation in Python

Karolis Urbonas

Head of Data Science, Amazon

What is RFM segmentation?

Behavioral customer segmentation based on three metrics:

  • Recency (R)
  • Frequency (F)
  • Monetary Value (M)
Customer Segmentation in Python

Grouping RFM values

The RFM values can be grouped in several ways:

  • Percentiles e.g. quantiles
  • Pareto 80/20 cut
  • Custom - based on business knowledge

We are going to implement percentile-based grouping.

Customer Segmentation in Python

Short review of percentiles

Process of calculating percentiles:

  1. Sort customers based on that metric
  2. Break customers into a pre-defined number of groups of equal size
  3. Assign a label to each group
Customer Segmentation in Python

Calculate percentiles with Python

Data with eight CustomerID and a randomly calculated Spend values.

dummy_percentile_data

Customer Segmentation in Python

Calculate percentiles with Python

spend_quartiles = pd.qcut(data['Spend'], q=4, labels=range(1,5))

data['Spend_Quartile'] = spend_quartiles
data.sort_values('Spend')

Customer Segmentation in Python

Assigning labels

  • Highest score to the best metric - best is not always highest e.g. recency
  • In this case, the label is inverse - the more recent the customer, the better

Customer Segmentation in Python

Assigning labels

# Create numbered labels
r_labels = list(range(4, 0, -1))

# Divide into groups based on quartiles recency_quartiles = pd.qcut(data['Recency_Days'], q=4, labels=r_labels)
# Create new column data['Recency_Quartile'] = recency_quartiles
# Sort recency values from lowest to highest data.sort_values('Recency_Days')
Customer Segmentation in Python

Assigning labels

As you can see, the quartile labels are reversed, since the more recent customers are more valuable.

recency_quartiles

Customer Segmentation in Python

Custom labels

We can define a list with string or any other values, depending on the use case.

# Create string labels
r_labels = ['Active', 'Lapsed', 'Inactive', 'Churned']

# Divide into groups based on quartiles recency_quartiles = pd.qcut(data['Recency_Days'], q=4, labels=r_labels) # Create new column data['Recency_Quartile'] = recency_quartiles # Sort values from lowest to highest data.sort_values('Recency_Days')
Customer Segmentation in Python

Custom labels

Custom labels assigned to each quartile

Recency_quartiles

Customer Segmentation in Python

Let's practice with percentiles!

Customer Segmentation in Python

Preparing Video For Download...