Customer Segmentation with RFM analysis – Part 1

In this post we explore how to segment customers based on their value to business.

The Pareto Rule

The 80–20 or Pareto Rule is a powerful one. In 1896, Vilfredo Pareto showed us that 80% of the land in Italy was owned by just 20% of the people. It was soon realized that this 80–20 imbalance comes up a lot in the world.

  • The richest 20% of humans have 82.7% of the world’s income.
  • 20% of words account for 80% of all words spoken
  • 20% of customers are responsible for 80% of profits
  • 80% of the complaints received by a business come from 20% of the customers
80% of coffee is consumed by 20% of office workers

This means that some customers are more profitable than others. But to be profitable in the long term, managers must have a clear understanding of how profitability correlates with customer segmentation. Recognizing differences between different segments of customers allows managers to tailor their approach to the needs of each segment.

What is customer segmentation?

Customer segmentation is the practice of dividing a customer base into groups of individuals that are similar in specific ways. You can provide different value propositions to different customer groups. Customer segments are usually determined on similarities, such as personal characteristics, demographics or spend patterns.

RFM Analysis

A popular marketing technique, RFM focuses on 3 important metrics:

  • Recency
  • Frequency
  • Monetary Value or Revenue

“RFM (recency, frequency, monetary) analysis is a marketing technique used to determine quantitatively which customers are the best ones by examining how recently a customer has purchased (recency), how often they purchase (frequency), and how much the customer spends (monetary).”

With RFM a business can divide customers into three segments:

  • Low Value: Customers who are less active than others, not very frequent buyer/visitor and generates very low — zero — maybe negative revenue.
  • Mid Value: In the middle of everything. Often using our platform (but not as much as our High Values), fairly frequent and generates moderate revenue.
  • High Value: The group we don’t want to lose. High Revenue, Frequency and low Inactivity.

The next sections cover Data Description, Methodology, Model Validation, Prediction and Conclusion.

Data Description

In our analysis we consider two different datasets belonging to separate companies. This helps to ensure validity of our models across different businesses. Lets call these two Companies A and B. The below table summarizes how many customers and transactions are available in our data for each company.

To calculate the required metrics, the data has been prepared at a particular level. In our processed sales dataset, one row shows one order of a product, along with its quantity, unit price and invoice date. We also know which customer bought the product.

The columns needed for the analysis are:

A minimal data requirement — in our analysis we have this for 2 companies

Creating RFM Segments

First we need to calculate Recency, Frequency and Monetary Value scores for each customer. We have some formulae that we can use:

  • Recency: Most recent date of purchase in our dataset – Most recent purchase date of the customer
  • Frequency: Calculate the total orders for each customer
  • Monetary Value: Calculate the Total Revenue from each Customer

Let’s have a detailed look at how the recency scores are calculated and how we can apply unsupervised machine learning to create clusters to group our recency scores. The same method will apply to our other two metrics as well.

We calculate Recency for each customer and get a table like:

One row shows one customer and their Recency in days. Lower Scores are better.

The next step is to cluster the recency scores to create groups. Suppose we have Recency scores for each customer with a range of 200–1000. It will help us to cluster these scores into groups of lets say 0–7 so that good score of 200 will be in cluster 7 and a bad score of 1000 will be in cluster 0.

To cluster the scores into groups, we will use a simple clustering technique called k-means. The first step is to find how many clusters we should group into. We will do this by checking an elbow plot.

Elbow Plot

In this plot we see that most of the variation in our Recency scores can explained by 2 clusters. For reasons explained later, we choose to go with 8 clusters of Recency scores.

Now we use k-means algorithm on our Recency scores and create clusters.

Assigning clusters to recency scores

We repeat the above procedure and get 8 clusters each for Frequency and Monetary value scores. After these steps our data looks like:

Now entering the last stage of RFM Clustering, we create a column ‘Overall Score’ which is just an addition of the Cluster values of our 3 metrics.

At last we will use this Overall Score to create the RFM segments. The range of Overall Score is 0–17. Here’s where we see why we chose 8 clusters earlier in the article — It’s good to have a bigger range of 0–17 rather than 0–5 because it allows us to segment Overall Scores in finer detail. Based on personal observation, while trying to maximise the difference between segments we choose the following:

  • Segments 0–6: Low Value
  • Segments 7–11: Mid Value
  • Segments 11–17: High value

Great! We now have RFM Segments for High, Mid and Low value customers. Lets examine the three metrics in scatter plots, plotted against each other.


From these plots we can infer that the RFM segments behave different from each other and in a predictable way. We seem to be successfully capturing behavior patterns with the segments, but there is some work left to do.

In the next post we will continue with Model Validation, Prediction and Conclusion.


  • RFM customer analysis for product-oriented services and service business development by Stormi, Lindholm, Laine, Korhonen
  • Data Driven Growth by Baris Karaman
  • Zipf Mystery by Micheal Stevens
Aman Prasad is a music, deep space and data science enthusiast.