RFM Analysis For Successful Customer Segmentation using Python

“RFM is a method used for analyzing customer value”.

It groups customers based on their transaction history :

  • Recency — How recently did the customer purchase?
  • Frequency — How often do they purchase?
  • Monetary Value — How much do they spend?

Combine and groups them into different customer segments for easy recall and campaign targeting. It’s super useful in understanding the responsiveness of your customers and for segmentation driven database marketing.

The resulting segments can be ordered from most valuable (highest recency, frequency, and value) to least valuable (lowest recency, frequency, and value). Identifying the most valuable RFM segments can capitalize on chance relationships in the data used for this analysis.

Let's look at the practical implementation of RFM segmentation

For RFM analysis, We need a few details of each Customer:

  • Customer ID / Name / Company etc — to identify them
  • Recency (R) as days since last purchase: How many days ago was their last purchase? Deduct most recent purchase date from today to calculate the recency value. 1 day ago? 14 days ago? 500 days ago?
  • Frequency (F) as the total number of transactions: How many times has the customer purchased from our store? For example, if someone placed 10 orders over a period of time, their frequency is 10.
  • Monetary (M) as total money spent: How many $$ (or whatever is your currency of calculation) has this customer spent? Simply total up the money from all transactions to get the M value.

To extract these values, we only need the following columns from dataset.


Create the RFM Table

  • In the dataset, the last order date is May 31, 2005, we have used this date as NOW date to calculate recency.

Now we have RFM values with respect to each customer

Let's work on the RFM score. We have used Quintiles — Make four equal parts based on available values — to calculate the RFM score.

RFM segmentation readily answers these questions for your business…

  • Who are my best customers?
  • Which customers are at the verge of churning?
  • Who are lost customers that you don’t need to pay much attention to?
  • Who are your loyal customers?
  • Which customers you must retain?
  • Who has the potential to be converted into more profitable customers?
  • Which group of customers is most likely to respond to your current campaign?

Some of them are:

Q. Who are my best customers?

Q. Which customers are at the verge of churning?

Q. Who are the lost customers?

Q. Who are loyal customers?

Versions of the RFM Model

RFM is a simple framework to quantify customer behaviour. Many people have extended the RFM segmentation model and created variations.

Two notable versions are:

  • RFD (Recency, Frequency, Duration) — Duration here is time spent. Particularly useful while analyzing consumer behaviour of viewership/readership/surfing oriented products.
  • RFE (Recency, Frequency, Engagement) — Engagement can be a composite value based on time spent on a page, pages per visit, bounce rate, social media engagement etc. Particularly useful for online businesses.

You can perform RFM for your entire customer base, or just a subset. For example, you may first segment customers based on a geographical area or other demographics, and then by RFM for historical, transaction-based behaviour segments.

Our recommendation: start with something simple, experiment, and build on.



NLP professional at Legato Health Technologies

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store