RFM (Recency, Frequency, Monetary) Customer Segmentation in Python

The below script shows how we may handle RFM segmentation with Python. RFM stands for Recency, Frequency and Monetary:

  • Recency: How many days since they last purchased
  • Frequency: Total purchase count by customer
  • Monetary: Total spend by customer

This method enables us to group our customers & target specific groups with advertisements or deals. The way we approach the task is:

  • Calculate the quartiles for recency, frequency and monetary
  • Segment those into quartiles, where quartile 2 and 3 are joined to become a ‘moderately engaged’ quartile
  • Create an RFM score from the quartiles. So, if my recency is 1, frequency is 2 and monetary is 1, my score will be 121
  • Using the scores, bucket the customers into specific groups

The below provides an example where we’ve used seaborn to plot the output: