CRM Analytics : Customer Segmentation & Customer Lifetime Value Prediction

Cem ÖZÇELİK
9 min readMay 19, 2022

--

Hello everyone, after a long time, we are together with you again in a new case. Today, in the data age, a study is carried out on the customer relationship management of businesses and customers, which have a great role in the continuity and profitability of businesses.

Gaining the loyalty of a customer is a very important issue for a business to maintain its profitability. As we can understand from the studies conducted in this field, retaining a customer is much more economical and profitable than acquiring a new customer. In fact, to add an interesting statistic in this regard, the cost of acquiring a new customer reveals an extra cost that can vary between 5 and 10 times the cost of retaining an existing customer. Even if we look at this scenario from a different perspective, we can say that losing an existing customer may cause both the elimination of the added value added by the existing customer to the company and the increase in the expenses of the company when finding a new customer to replace the old customer.

So, where should we start to retain our current customers in order to best manage the customer factor that has such an impact on our business? What steps need to be taken to make those who buy your products and services more committed to your company? How can you identify the current needs, demands and complaints of your customers? Starting from these questions, we can look at different performance metrics and calculations in the scientific world.

Let’s go over the customer lifetime value, which is the most important metric that we come across here and which you will encounter in this study as well. So what is the customer lifetime value?

In a simple description, customer lifetime value can also be defined as the expected return on investment made for a customer over a certain period of time. Or, to be a little more descriptive, as another description, “The profit made from the first purchase a customer makes from your business to the time they stop shopping” gives the customer lifetime metric.

The result we have obtained from these two short explanations is a metric used in the processes of customer lifetime value, gaining new customers, increasing the tendency to buy with direct or cross-selling methods, tracking customer behaviors and making strategic decisions.

Customer lifetime value, which is one of the important performance criteria, cannot be calculated accurately by many businesses today. By calculating the customer lifetime value metric correctly, you can decide the cost you have to spend to acquire a customer. You can even predict more profitable for your business whether to gain new customers or increase revenue from existing customers.

After explaining what the customer lifetime value is, we will perform a sample customer segmentation study using the data of an e-shopping site and then calculate the customer lifetime value for these customers.So let’s start !

First, let’s import the libraries and packages that we will use in the study.

Then let’s import our sample data set to be used in the study.

output of this line of code:

Overview of the dataset

After taking a good look at our dataset, let’s look at our descriptive statistics for exploratory data analysis of the dataset.

The output of this image is as follows:

Descriptive statistics of the data set

We looked at the descriptive statistics of the dataset. Now let’s see the distribution of the shopping that took place on the shopping site according to the regions.

Sales according to regions

After seeing the division of our total sales by regions, let’s look at the numerical variables in more detail and see the outliers and missing values.

Descriptive Statistics

The information we obtained when we looked at these statistics is listed below:

  • As we can see, some variables have missing values. The missing values of the Quantity and UnitPrice variables need to be cleared.
  • There are negative values in UnitPrice and Quantity. That mean is cancelled orders.
  • Quantity and Unit Price should be multiplied to create Total Price.
  • Missing values in Customer ID and Description.
  • InvoiceDate should be datetime, not object.

After making these inferences based on descriptive statistics, we can move on to data preprocessing.

Data Pre-Processing :

First, let’s clean up the missing values in the data set.

The output we get in this code blog is as follows:

We talked about canceled orders in our dataset. These data are data lines that start with the “c” character in the “Invoice No” column. We need to delete canceled orders from our dataset.

After deleting canceled orders datasets from our dataset, we also delete outliers from our dataset.

We create Total Price variable and look at the descriptive statistics again according to the new version of the data set.

New Descriptive Statistics

We have finished the preprocessing of our dataset. After the data preprocessing, we will dwell on the RFM analysis. First, we explain RFM and then RFM analysis work for our dataset.

RFM Analysis :

What is RFM Analysis? This is the question we must first clarify. RFM, stands for Recency, Frequency, and Monetary value, each corresponding to some key customer trait. In other words, it is some numerical value analysis that summarizes customer behavior. The reason we summarize in this way is simply put: frequency and monetary value affect a customer’s lifetime value, and innovation affects retention, which is a measure of engagement.

As a result of RFM Analysis:

  • With the closeness of the purchase date to the current date, we can measure the customer’s sensitivity to promotions.
  • At the same time, we can conclude that the more often the customer buys, the more interested and satisfied they are.
  • Monetary value separates heavy spenders from low value buyers

Now that we have explained the RFM analysis, we can work on the metrics that we will use while performing the RFM analysis.

Now we will be performing some manipulations on our dataset. What we will do is to create a data set first and group this data according to CustomerIDs. We will find the closeness between the most recent shopping record and today by aggregating the records grouped in CustomerID with the aggregation function. This will be represented as “Recency” in our new dataset. Likewise, each unique value in the “InvoiceNo” variable will represent the frequency of our respective customer and will be represented by the “Frequency” column name in our new dataset. Finally, we will find the size of the expenses incurred by the relevant customer by aggregating according to the “TotalPrice” variable that we have created in the above sections. This value is associated with the name of the “Monetary” column.

New Dataset Looking

We created our new dataset and looked at its new look. Now we divide our customers into layers or segments as another visual. For this, we create an RFMScore variable by making use of the “Recency”,”Frequency”,”Monetary” variables in the new data set we have just created. We will also examine the volume of our customers that we have segmented into this segment with a visual.

RFM Dataset
Segmentation

We will analyze our data set, which we have separated by segmentation, by grouping the segments within themselves.

Segment Analysis -1–
Segment Analysis
Relationship Recency&Frequency by Segments

In the segmentation study, we use the K-Means Algorithm and the Elbow method to determine the optimum number of clusters. Thus, the value of X with the most breakouts is our optimal number of clusters.

Elbow Method

“Silhouette Score” is one of the most used measurement metrics when we do not have the basic reality. The silhouette coefficient for a data point is (bi−ai)/max(bi,ai). The average distance (ai) between a data point and all other data points in the cluster is the average distance (bi) from all other data points in the cluster closest to that data point. “Davies Bouldin Score” is also used to measure the mean similarity between clusters. Low values are preferred for this ratio and the minimum score value is 0.

Segment Analysis

Segment Analysis
Segment Analysis
K-Means Segment

Customer Life Time Value (CLTV) :

In the last part of our article, we will focus on the Customer Lifetime Value issue that we mentioned at the beginning. Afterwards, we will calculate the Customer Lifetime Values of our customers, which we have segmented in the RFM Analysis.

Customer Life Time Value

Now we will create some new metrics. For example average order value etc.

BG / NBD:

BG/NBD models assume that the number of transactions made by each customer follows a Poisson process with a heterogeneity in transaction rates across customers following a gamma distribution. These assumptions give us a Negative binomial distribution (NBD) for modeling the number of transactions made by the customer while he is alive.

Top 10 Expected Number of Transaction (1 Week) ->

Top 10 Expected Number of Transaction (1 Month) ->

Total Expected Number of Transaction (1 Month) ->

Frequency of Repeat Transactions ->

Frequency of Repeat Transactions

Gamma — Gamma Submodel :

It is a model used in estimating the amount of purchases made per transaction by the future customer.

The properties of Gamma-Gamma model are:

Monetary value of users’ transactions is random around their mean transaction value.

Mean transaction value varies across users but doesn’t vary for an individual user over time.

Mean transaction values is Gamma distributed across customers.

Top 10 Expected Average Profit ->

The Final CLTV :

Customer Life Time Values(6 Months)
Average Of CLV by Segments

We have come to the end of one of our studies. Stay tuned until we see you in our next case.

--

--