Marketing Analytic — Measuring Customer Lifetime Value (CLTV) | by Sarit Maitra | Towards Data Science

https://sarit-maitra.medium.com/membership
Customer Life time Value (CLTV) is a quantitative analysis and one of the most important metric to modern customer centric business scenario. It has been a mainstay concept in direct response marketing for many years, and has been increasingly considered in the field of marketing. Here, we will experiment with a implementable CLTV model that is useful for market segmentation and the allocation of marketing resources for acquisition, retention, and cross-selling. The selection of the model is based on a systematic theoretical taxonomy and on assumptions embedded in customer behavior.
Relevant data is always a basis on any prediction and CLTV is no exception to that. Here are some of the examples / questions we may want to answer:
How much money has every particular customer already spend at your shop?
How long has every particular customer actually been customer?
How old is every particular customer? Age is an important part of customer’s portrait.
How did every particular customer respond to the discounts and offers? If we know who is more likely to react, we can formulate strategy and spend the marketing funds exactly on these people, and get a result.
The goals of this article lies in the studying of the business problems as mentioned below. I will demonstrate, as how to build a prediction model using Linear Regression for CLTV.
How to Identify the most profitable customers?
How can a company offer the best and make the most ?
How to segment profitable customers?
How much budget need to spend to acquire customers?
There are few approaches available to compute CLTV.
Let’s use some simple equations:
Customer Value = Average Order Value (AOV)* Purchase Frequency
Churn Rate: Churn Rate is the % of customers who have not ordered again.
Customer Lifetime = 1/ churn rate
Churn Rate= 1-Repeat Rate
Let’s get the data and jump into the insights to explore what we have in the data.
The bar chart clearly shows that we have maximum number of business coming from the UK. From descriptive statistics, we can see that, the some of the order in a negative quantity. This is practically not possible. This could be the order cancellation or return materials. So, we need to filter Quantity greater than zero. More so, we also will filter the required columns for the CLTV analysis. We need CustomerID, InvoiceDate, InvoiceNo, Quantity, and UnitPrice from the data set.
data = uk_data[(uk_data[‘Quantity’]>0)]data=uk_data[[‘CustomerID’,’InvoiceDate’,’InvoiceNo’,’Quantity’,’UnitPrice’]]data[‘TotalPurchase’] = uk_data[‘Quantity’] * uk_data[‘UnitPrice’]
Now, we shall compute (a) the number of days between the present date and the date of last purchase from each customer, (b) the number of orders for each customer, (c) the sum of purchase price for each customer. Also do further data purification by renaming the columns.
data_group= data.groupby(‘CustomerID’).agg({‘InvoiceDate’: lambda date: (date.max() — date.min()).days, ‘InvoiceNo’: lambda num: len(num), ‘Quantity’: lambda quant: quant.sum(), ‘TotalPurchase’: lambda price: price.sum()})# Change the name of columnsdata_group.columns=[‘num_days’, ’num_transactions’, ’num_units’, ’spent_money’]data_group.head()
Now, we shall compute CLTV using the formulas mentioned earlier.
# Average Order Valuedata_group[‘avg_order_value’]=uk_data_group[‘spent_money’]/uk_data_group[‘num_transactions’]#Purchase Frequency purchase_frequency=sum(uk_data_group[‘num_transactions’])/uk_data_group.shape[0]# Repeat Raterepeat_rate=uk_data_group[uk_data_group.num_transactions > 1].shape[0]/uk_data_group.shape[0]#Churn Ratechurn_rate=1-repeat_ratepurchase_frequency,repeat_rate,churn_rate
#Output: (90.37107880642694, 0.9818923743942872, 0.018107625605712774)
Let’s assume that business making 25% profit.
# Profit Margindata_group[‘profit_margin’]= data_group[‘spent_money’]*0.25# Customer Valuedata_group[‘CLTV’]= data_group[‘avg_order_value’]*purchase_frequency)/churn_rate#Customer Lifetime Valuedata_group[‘cust_lifetime_value’]=data_group[‘CLTV’]*data_group[‘profit_margin’]
Now we are going to predict CLTV using Linear Regression Model. We need some data preparation here before pushing the data to regression model.
uk_data['month_yr'] = uk_data['InvoiceDate'].apply(lambda x: x.strftime('%b-%Y')) # Extract month and year from InvoiceDate.
# creating a pivot table taking the columns as input, and groups the entries into a two-dimensional table in such a way that provides a multidimensional summation of the data.sale=uk_data.pivot_table(index=[‘CustomerID’],columns=[‘month_yr’],values=’TotalPurchase’,aggfunc=’sum’,fill_value=0).reset_index()sale[‘CLV’]=sale.iloc[:,2:].sum(axis=1) # sum all the months salesale.head()
Now, let’s build a regression model for existing customers. We need a set of dependent (y) and independent variables (X). So, we shall take last six-months data as independent variables and total revenue over three years as a dependent variable followed by usual ML process of splitting training & test data.
X=sale[[‘Dec-2011’,“Nov-2011”, ‘Oct-2011’,“Sept-2011”,’Aug-2011',’Jul-2011']]y=sale[[‘CLV’]]#split training set and test setX_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)linreg = LinearRegression() # instantiatelinreg.fit(X_train, y_train) # fitting the model to the training datay_pred = linreg.predict(X_test) # make predictions on the testing setprint(linreg.intercept_)print(linreg.coef_)
Let’s print R-squared which is the proportion of variance explained by the model, Mean Absolute Error (MAE), Mean Squared Error (MSE), Root Mean Squared Error (RMSE).
print(“R-Square:”,metrics.r2_score(y_test, y_pred))print(“MAE:”,metrics.mean_absolute_error(y_test,y_pred))print(“MSE”,metrics.mean_squared_error(y_test, y_pred))print(“RMSE:”,np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
R-Square: 0.9666074402817513
MAE: 595.0282284701232
MSE 2114139.8898678916
RMSE: 1454.008215199588
When the model is deployed, the ML algorithm helps to understand the patterns; it will also categorize the customers according to their CLTV predictions. The marketing strategy is important here considering that CLTV can figure out most profitable customers, but how we are going to make profit from them, will depend on the adopted marketing strategy. Moreover loyalty programs can be formulated based on the insights.
It is not clear how a regression model can be used to forecast the dynamics of buyer behavior well into the future and then tie it all back into a present value for each customer.
Two periods of purchasing behavior are required — (a) to define the RFM variables 1 and (b) to arrive at values of the dependent variable(s). It would be better if we were able to create predictions of future purchasing behavior simply using period 1 data alone. Moreover, it would be of best interest to leverage all of the available data for model calibration purposes without using any of it to create a dependent variable for a regression-type analysis.
The RFM variables are only imperfect indicators of underlying behavioral traits. Different “slices” of the data will yield different values of the RFM variables and therefore different scoring model parameters. This has important implications when we utilize the observed data from one period to make predictions of future behavior (2) (3).
The LR was close to perfect here predicting what an average customer will spend during their lifetime. CLTV helps to design an effective business plan and also provide a chance to scale the business. However, as already discussed, a lot will depend on marketing strategy to extract profit. In general, marketing automation platform manages the customer lifecycle. Marketing platforms orchestrate the marketing campaigns while also automating the movement of leads and customers through the pipeline. Marketing departments use these software applications to plan, coordinate, execute, manage, and measure their campaigns across multiple channels and automate repetitive tasks.
I can be connected here .