Customer Segmentation with RFM

Ahmet Okan YILMAZ
3 min readMar 13, 2022

--

What is Customer Segmentation?

Customer segmentation is the process of dividing customers into groups based on common characteristics / behaviours. There are some segmentation techniques. And RFM is one of them.

What is RFM?

RFM analysis is a customer segmentation technique used to quantitatively rank and group customers based on three metrics. RFM is also a simple but effective segmentation technique.

Source: https://cdn.hackernoon.com/images/ARCWTrgYpoc531106B2eMedWoT42-8w1376c.jpeg

RFM Metrics

RFM stands for three dimensions: Recency, frequency and monetary.

R for how recently did the customer purchase? This information can be used to remind recent customers to revisit the business soon to continue meeting their purchase needs.

F for how often do the customer purchase? Predicting this can assist marketing efforts directed at reminding the customer to visit the business again.

M for how much do the customer spend? While this can produce a better return on investment in marketing and customer service, it also runs the risk of alienating customers who have been consistent but have not spent as much with each transaction.

RFM Segments

Source: https://cdn.enhencer.com/website-assets/images/blog/AdvantagesAndInefficaciesOfRFMSegmentation1.png

Champions: Your best customers, they buy and spend a lot and made their last purchase recently.

Loyal Customer: Very good customers. They spend a lot.

Potential Loyalist: Recent customers, but who have already spent a lot.

New Customer: Recent customers, who made only a few purchases.

Promising: Customers who buy frequently and spend a lot, but made their last purchase some time ago.

Need Attention: Customers with recency and above-average spending.

At Risk: Customers who bought frequently, but haven’t made any purchases in a long time.

Can’t lose them: Customers who have spent a lot, but have been inactive for a long time.

Hibernate: Low-frequency, low-spender customers who haven’t bought in a long time.

Lost: Your worst customers. They haven’t bought in a long time, they only bought once and they spent very little.

How to perform RFM Analysis using Python?

And now, let’s build an RFM analysis with python.

We can drop null values and return invoices. Return invoices contains a “C” character in the Invoice column.

Then filter Quantity and Price columns. Because there are some negative values.

Create a TotalPrice feature multiply by Quantity and Price.

Convert dtype of the InvoiceDate to datetime. We will calculate the time elapsed since the last purchase. So we need last purchasing time.

Now, we can create rfm table.

Change the column names.

Calculate the rfm scores with pandas qcut function.

We will use only recency and frequency scores. Let’s combine them.

Finally, we can convert rfm scores to rfm segments using regex.

Kaggle: https://www.kaggle.com/ahmetokanyilmaz/customer-segmentation-with-rfm

Github: https://github.com/aoyilmaz/DataScience_Projects/blob/main/CRM/RFM/rfm.py

Sources:

Mehmet Akturk, Veri Bilimi Okulu

Mustafa Vahit Keskin, Veri Bilimi Okulu

--

--

Ahmet Okan YILMAZ
Ahmet Okan YILMAZ

Written by Ahmet Okan YILMAZ

Industrial Engineer | Data Scientist | Factory Manager

No responses yet