Skip to content

Zhn-Rui/rfm-customer-segmentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Customer Segmentation Analysis with RFM Model

Project Overview

This project analyzes customer purchasing behavior using the Online Retail dataset and applies the RFM model (Recency, Frequency, Monetary) to segment customers into meaningful business groups.

The goal is to identify high-value customers, loyal customers, and potentially lost customers, so that firms can design more targeted retention, reactivation, and revenue growth strategies.

Tech Stack

  • Language: Python 3
  • Libraries: pandas (Data manipulation), numpy (Vectorized operations), matplotlib & seaborn (Data visualization)
  • Methodology: RFM Analysis, Cohort Segmentation, Vectorized Conditional Logic

Dataset

  • Source: UCI Machine Learning Repository
  • Dataset Name: Online Retail
  • Period Covered: 2010-12-01 to 2011-12-09
  • Rows after cleaning: 397,884
  • Unique customers: 4,338

The dataset contains transactional records for a UK-based online retailer, including invoice information, purchase quantity, price, customer ID, and invoice date.

Business Problem

Retailers often have thousands of customers, but not all customers contribute equally to revenue.
A company needs to understand:

  • Which customers are the most valuable?
  • Which customers are loyal and worth retaining?
  • Which customers are at risk of churn?
  • Which low-value customers should receive lower marketing priority?

To answer these questions, this project uses RFM segmentation.

Methodology

1. Data Cleaning

The following cleaning steps were applied:

  • Removed returned orders (Quantity <= 0)
  • Removed zero or negative prices (UnitPrice <= 0)
  • Dropped missing CustomerID
  • Converted InvoiceDate to datetime format
  • Created a new variable: Revenue = Quantity × UnitPrice

2. RFM Calculation

For each customer, three metrics were calculated:

  • Recency: Number of days since the customer’s last purchase
  • Frequency: Number of unique invoices
  • Monetary: Total revenue generated by the customer

3. RFM Scoring

Each customer received a score from 1 to 5 on:

  • Recency
  • Frequency
  • Monetary

These scores were combined into an RFM_score.

4. Customer Segmentation

Customers were assigned to one of the following business segments:

  • Champions
  • Loyal Customers
  • Big Spenders
  • Potential Loyalists
  • At Risk
  • Lost Cheap
  • Regular

Results

Customer Segmentation Overview

The final segmentation results are:

  • Regular: 983
  • Champions: 962
  • Lost Cheap: 824
  • Loyal Customers: 758
  • At Risk: 454
  • Potential Loyalists: 288
  • Big Spenders: 69

Key Insights

  1. Regular customers form the largest segment, suggesting that many customers have moderate but not highly differentiated purchasing behavior.
  2. Champions represent one of the largest groups, indicating a strong core customer base with recent, frequent, and high-value purchases.
  3. Loyal Customers also account for a substantial share, showing that the retailer has a meaningful repeat-customer foundation.
  4. Lost Cheap customers are numerous, but they likely contribute relatively limited revenue and may not deserve the same marketing priority as high-value segments.
  5. At Risk customers are particularly important from a managerial perspective, because they were previously valuable but have not purchased recently.
  6. Big Spenders are a very small segment, which suggests that a limited number of customers generate unusually high spending and may deserve highly personalized treatment.

Visualization

The main customer segmentation chart is shown below:

RFM Segmentation

Business Recommendations

Based on the segmentation results, the retailer could consider the following strategies:

  • Champions: reward with VIP programs, exclusive offers, and early product access
  • Loyal Customers: maintain engagement through loyalty campaigns and personalized recommendations
  • Potential Loyalists: encourage repeat purchases with targeted promotions
  • At Risk: design reactivation campaigns such as win-back emails or time-limited discounts
  • Big Spenders: provide premium service and tailored offers
  • Lost Cheap: use low-cost automated campaigns only, with limited marketing investment
  • Regular: nurture toward higher engagement through product recommendations and retention messaging

How to Run

  1. Clone the repository.
  2. Ensure you have the required libraries installed: pip install pandas numpy matplotlib seaborn openpyxl
  3. Run the analysis script from the root directory:
    python notebooks/analysis.py
    

Project Structure

PythonProject/
│
├── data/
│   └── Online Retail.xlsx
│
├── images/
│   └── rfm_segmentation.png
│
├── notebooks/
│   └── analysis.py
│
└── README.md

About

Customer segmentation analysis using the RFM model to identify high-value consumer groups.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages