← Back to Projects

RFM Customer Segmentation

Demo

Explore the project on GitHub →
View the Dashboard via the Streamlit App →

Problem

Businesses often struggle to understand which customers are most valuable and which are at risk of leaving. The goal of this project was to segment customers based on purchasing behavior using RFM analysis.

Data

The dataset contains transaction history including purchase dates, frequency, and monetary value. It was cleaned and aggregated to build customer-level metrics.

Approach

I used the RFM framework. RFM analysis is a marketing technique used to segment customers based on:

  • Recency: How recently a customer made a purchase.
  • Frequency: How often they purchase
  • Monetary: How much revenue they generate

These scores are combined to classify customers into behavioral segments such as Champions, Loyal Customers, At Risk, and Lost Customers. These classifications support targeted marketing strategies.

Implementation

I calculated RFM scores using Python and Pandas, then segmented customers into groups such as Champions, Loyal Customers, At Risk, and Lost Customers.


I decided on the following segments:

  • Champions: The absolute best customers.
  • Loyal Customers: Customers that are loyal to the business but are not yet at highest level.
  • Potential Loyalists: Customers that have potential to become loyal.
  • Cannot Lose Them: Customers that are valuable and need urgent attention.
  • At Risk: Customers that are at risk of churning.
  • Needs Attention: Customers that are in the middle-of-the-pack. With attention, can potentially become loyal.
  • Lost Customers: Customers that have been lost.
  • New Customers: Customers that have purchased recently but don't have much time with the business.

Visualization was done using Plotly to analyze distribution across segments, and visualizations were presented using Streamlit.

Results

The segmentation revealed clear behavioral clusters that can be used in targeted marketing and advertisement. The dashboard makes it simple to target specific segments, and can be easily updated whenever the dataset changes.

What I Learned

This project strengthened my understanding of data aggregation, feature engineering, data visualization, and dashboard design.

How I Would Improve This Project in the Future

  • I would clean up the project structure and introduce packaging via pyproject.toml.
  • I would allow users to upload their own datasets and explore segments using the dashboard.
  • I would condense the amount of segments used. I feel that I used too many segments in this project. If I were to keep a few segments, I would keep the primary four: Champions, Loyalists, At Risk, Lost Customers.
View on GitHub →