CRM Analytics — Customer Segmentation with RFM Analysis

Bedirhan Hasançebi
4 min readMar 5, 2023

--

Hello, in this article I will introduce CRM Analytics and try to explain how to do Customer Segmentation with RFM Analysis.

First, let’s talk about why something like CRM Analytics (Customer Relationship Management) is important for companies. In short, CRM Analytics is to manage all the communications and relationships a company has with its customers. By doing this, they try to keep themselves closer to their customers. As a result of the analysis of the internal data, strategies can be developed and decision-making processes can be managed according to the corporate policy. The purpose of CRM Analytics is to take decisions and create predictions that will increase profitability.

RFM Analysis is the classification process by creating three components: customers’ purchasing frequency, transaction currency and monetary value of transactions. Recency represents transaction timeliness, Frequency transaction frequency, and Monetary monetary value. The resulting scores are divided into segments, and the decision-making process begins by performing class analysis. Segments can be created based on RFM and RF scores while performing RFM analysis. We will perform RFM segmentation based on the RF scores and we will get the segments from the RF matrix.

As seen in the table above, segments change depending on the Recency and Frequency scores. For example, customers with a recency of 3 or 4 and a Frequency of 4 or 5 are segmented as Loyal Customers. Segments made up of RF scores must be evaluated and analyzed together with Monetary scores. Now let’s begin our RFM Analysis with our sample dataset.

import datetime as dt
import pandas as pd
df_ = pd.read_excel("datasets\online_retail_II.xlsx", sheet_name="Year 2009-2010")
df = df_.copy()
df.head()
df.isnull().sum()

First of all, we import our data set and required libraries. You can access this dataset at (https://archive.ics.uci.edu/ml/datasets/Online+Retail+II) link. The dataset contains the customer and sales information of an e-commerce company that sells souvenirs. We will work with the data from 2009 to 2010. Let’s take a first look at the dataset and move on to analysis.

This data set consists of 525641 observations and 8 variables. The variables we work with are Customer Id, Invoice, Quantity, Price and InvoiceDate. We will calculate Recency with the variable Invoice and InvoiceDate, Frequency with Quantity, Price with Moantery. But first we need to calculate the value of each transaction. For each observation, we multiply the variables Quantity and Price to create the TotalPrice variable.

df.dropna(inplace=True)
df = df[~df["Invoice"].str.contains("C", na=False)]
df.isnull().sum()

After deleting the missing values and adding the Total Price variable, the dataframe looks like this:

To find the RFM scores, we will calculate the Recency, Frequency and Monetary scores by grouping according to the CustomerID variable, that is, by each customer. We will assign what we find to the rfm dataframe. Calculating the Recency score, Frequency score, and Monetary score using the qcut function.

Let’s define the dictionary to do the segmentation

seg_map = {
r'[1-2][1-2]': 'hibernating',
r'[1-2][3-4]': 'at_Risk',
r'[1-2]5': 'cant_loose',
r'3[1-2]': 'about_to_sleep',
r'33': 'need_attention',
r'[3-4][4-5]': 'loyal_customers',
r'41': 'promising',
r'51': 'new_customers',
r'[4-5][2-3]': 'potential_loyalists',
r'5[4-5]': 'champions'
}

Now do the segmentation and find RFM score.

In this way, we can divide our customers into groups and develop a separate marketing strategy for each group, and enable them to shop more from us.

Thanks for reading this text.

Resources:

Subscribe to Innovators’ Hub for more content.

Want to write for Innovators’ Hub ?

Fill out this form: https://docs.google.com/forms/d/1wAs5hOW0aunNyZjJdd8mqFJsnbxzPSxy0_KtciM9kIU/edit#responses

--

--