General problems and strategies in Database Marketing

  1. Customer retention, which sometimes can be even more important than customer acquisition. For example, according to research, a 5% increase in customer retention could increase company profitability from 25% to 85%. [1]

Issues Tackeld in this post using an open online retail dataset [2]

  1. How predicting customer lifetime values helps you define customer segmentation - hence derives segment specific marketing strategies

(1) Prelimiary data exploration for customer segments using basic RFM implementation in Python


  • R means Recency: it is the time from the last transaction of the customer to current time
  • F means Frequency: it is how many already made transactions the customer has had overall
  • M means Monetary value: it is how much money the customer has contributed overall
# import online retail dataset

import pandas as pd
import datetime as dt

df = pd.read_excel("Online_Retail.xlsx", sheetnames = "Online Retail", converters={'CustomerID': str})
df['ParsedInvoiceDate'] = df['InvoiceDate'].apply(lambda x: dt.datetime.strftime(x, "%Y-%m-%d"))
df.head()

df['ParsedInvoiceDateFrequency'] = df['InvoiceDate'].apply(lambda x: pd.to_datetime(x.date(), format="%Y-%m-%d"))
df['ParsedInvoiceDateRecency'] = df['InvoiceDate'].apply(lambda x: pd.to_datetime(x.date(), format="%Y-%m-%d"))

now = dt.datetime.now()
now = now.strftime("%Y-%m-%d")

data['Sales'] = data['UnitPrice']*data['Quantity']

# Group transactions into customer: 
# frequency(how many unique days a transaction happened), recency(last transaction until today), money(sum of all spend)
data = data.groupby(['CustomerID']).agg({'ParsedInvoiceDateFrequency': lambda x: x.nunique(),
                                         'ParsedInvoiceDateRecency': lambda x: pd.to_datetime(now, format="%Y-%m-%d") -   
                                         pd.to_datetime(x.dt.date.max(), format = "%Y-%m-%d"),
                                         'Sales': lambda x: sum(x)
                                        })
data.rename(columns = {"ParsedInvoiceDateFrequency": "Frequency", 
                       "ParsedInvoiceDateRecency": "Recency",
                       "Sales": "Monetary"
                      }, inplace=True)
data.head()

Reference

[1]: How to Model Your Cusotmers’ Lifetime Value

[2]: Online Retail Data Set

“Counting Your Customers” the Easy Way: An Alternative to the Pareto/NBD Model

⤧  Previous post Bayesian Ridge Regression For Prediction ⤧  Next post Analytics Applied in Marketing Research