...

/

Section 4: RFM Analysis

Section 4: RFM Analysis

In this lesson, the RFM analysis is applied to the dataset.

RFM analysis

RFM is a categorizing technique that uses the previous purchasing behavior of the customers to divide customers into groups so that an optimal marketing strategy can be developed for each individual. RFM stands for recency, frequency, and monetary, respectively.

  • Recency: How many days have passed since a customer has bought an item

  • Frequency: How many orders a customer has placed

  • Monetary: How much money a customer has spent

Need for RFM analysis

  • This technique efficiently categorizes the customers into specific rank-based groups taking into account their past online behaviors.

  • This can help marketers and advertisers target each group of consumers separately, enabling them to cater to the needs of groups instead of each individual.

  • This technique also informs us of the most and least profit yielding customers so relevant resources can be deployed to each group according to their needs.

  • If the results of this technique are correctly used, then even customers who don’t engage in much activity(view, cart, buy) can be influenced to be high potential customers.

RFM technique and steps to perform

In this process, the customers are separated into four groups under each of the RFM metrics, i.e., recency, frequency, and monetary. This means we’ll have a maximum of (4 x 4 x 4) sixty-four groups to deal with, which is not very large considering that the total number of customers can be in the thousands. Quantiles will be used to divide the customers into groups.

The following steps will be performed to get the final list of segmented customers.

Step 1: Get the purchase data of all customers.

Press + to interact
import pandas as pd
df = pd.read_csv("2019-Oct.csv") # Reading the data from file
#Convert the type of event_time column to datetime
df['event_time'] = pd.to_datetime(df.event_time)
# Get rows with event_type equals purchase
purchased = df[df['event_type'] == 'purchase']
# Filter relevant data from Data Frame
purchased = purchased[['user_id', 'user_session', 'event_time' ,'price']]
print(purchased)

On line 9, the rows from the DataFrame where event_type is assigned purchase value are selected.

On line 12, a subset of columns is selected to create a new DataFrame. This subset includes user_id, user_session, event_time, and price, as can be seen in the above output. These columns are selected based on their importance in computing the R, F, and M ...