RFM Analysis Analysis Using Python
In this article, we are going to see Recency, Frequency, Monetary value analysis using Python. But first, let us understand the RFM analysis briefly.
What is RFM analysis?
RFM stands for recency, frequency, monetary value. In business analytics, we often use this concept to divide customers into different segments, like high-value customers, medium value customers or low-value customers, and similarly many others.
Let’s assume we are a company, our company name is geek, let’s perform the RFM analysis on our customers
- Recency: How recently has the customer made a transaction with us
- Frequency: How frequent is the customer in ordering/buying some product from us
- Monetary: How much does the customer spend on purchasing products from us.
Loading the necessary libraries and the data
Here we will import the required module( pandas, DateTime, and NumPy) and then read the data in the dataframe.
Dataset Used: rfm
Here we are calculating recency for customers who had made a purchase with a company.
We are here calculating the frequency of frequent transactions of the customer in ordering/buying some product from the company.
Calculating Monetary Value
Here we are calculating the monetary value of customer spend on purchasing products from the company.
Merging all three columns in one dataframe
Here we are mering all the dataframe columns in a single entity using the merge function to display the recency, frequency, monetary value.
Ranking Customer’s based upon their recency, frequency, and monetary score
Here we are normalizing the rank of the customers within a company to analyze the ranking.
Calculating RFM score
RFM score is calculated based upon recency, frequency, monetary value normalize ranks. Based upon this score we divide our customers. Here we rate them on a scale of 5. Formula used for calculating rfm score is : 0.15*Recency score + 0.28*Frequency score + 0.57 *Monetary score
Rating Customer based upon the RFM score
- rfm score >4.5 : Top Customer
- 4.5 > rfm score > 4 : High Value Customer
- 4>rfm score >3 : Medium value customer
- 3>rfm score>1.6 : Low-value customer
- rfm score<1.6 :Lost Customer
Visualizing the customer segments
Here we will use a pie plot to display all segments of customers.