ds@mcpanalytics.aiEmail your data and your question and get an answer about your own data, with the method shown.Email your data and question. Get an answer.

RFM Customer Segmentation for E-Commerce

By MCP Analytics Team | Published , updated

Have an order history? Run RFM segmentation on your CSV: free, no signup →

You send the same email blast to your entire customer list. You run the same retargeting ads for everyone. You offer the same discount to a customer who bought yesterday and a customer who last bought eight months ago. RFM analysis segments your customers into named groups based on three numbers (how recently they bought, how often they buy, and how much they spend) so you can stop treating everyone the same and start putting your budget where it matters.

Worked Example: Scoring 30 Simulated Customers

Question: Which customer groups appear in a small sample of order history, and how much order revenue sits in each group?

Inputs: Simulated data, seed 23. The run uses 137 made-up orders from 30 customers and ends on 2025-01-01. Each order has a customer ID, date, and amount.

Method: For each customer, find days since the last order, count orders, and sum order amounts. Rank each measure into five equal-sized bands. A more recent order gets a higher R score; more orders and more revenue get higher F and M scores. Ties are broken by order of appearance, so with 30 customers each band holds exactly 6. Segments use the R and F scores only; M is scored and shown but does not set a segment. The segments come from the standard RFM tool's R and F rules.

Complete Python script:

"""Small RFM example using simulated order data."""
import numpy as np
import pandas as pd

SEED = 23
rng = np.random.default_rng(SEED)
reference_day = pd.Timestamp("2025-01-01")
rows = []
for i in range(1, 31):
    customer = f"C{i:02d}"
    orders = int(rng.integers(1, 9))
    last_days_ago = int(rng.integers(1, 366))
    for order_no in range(orders):
        # Earlier orders are placed before the customer's most recent order.
        gap = int(rng.integers(12, 55))
        days_ago = last_days_ago + (orders - order_no - 1) * gap
        amount = round(float(rng.uniform(18, 160)), 2)
        rows.append((customer, reference_day - pd.Timedelta(days=days_ago), amount))
orders = pd.DataFrame(rows, columns=["customer", "date", "amount"])
summary = orders.groupby("customer").agg(
    last_date=("date", "max"), frequency=("date", "size"), monetary=("amount", "sum")
)
summary["recency_days"] = (reference_day - summary["last_date"]).dt.days

# Rank customers into five equal-sized bands; high recency score means more recent.
def quintile(values, high_is_good=True):
    ranks = values.rank(method="first", ascending=high_is_good)
    return np.ceil(ranks * 5 / len(values)).astype(int)

summary["R"] = quintile(summary["recency_days"], high_is_good=False)
summary["F"] = quintile(summary["frequency"], high_is_good=True)
summary["M"] = quintile(summary["monetary"], high_is_good=True)

# Segments use the R and F scores only; M is scored but does not set a segment.
def segment(r, f):
    if r >= 4 and f >= 4: return "Champions"
    if r == 3 and f >= 4: return "Loyal"
    if r >= 4 and f in (2, 3): return "Potential Loyalist"
    if r >= 4 and f == 1: return "New Customers"
    if r == 1 and f >= 4: return "Can't Lose Them"
    if (r == 1 and f == 3) or (r == 2 and f >= 3): return "At Risk"
    if r <= 2 and f <= 2: return "Hibernating"
    return "Need Attention"

summary["segment"] = [segment(int(r), int(f)) for r, f in zip(summary.R, summary.F)]
segment_order = [
    "Champions", "Loyal", "Potential Loyalist", "New Customers",
    "Can't Lose Them", "At Risk", "Hibernating", "Need Attention",
]
print(f"Simulated data, seed {SEED}")
print(f"Input: {len(orders)} orders, {len(summary)} customers; "
      f"date window ends {reference_day.date()}")
print("Method: days since last order, order count, and summed order amount; "
      "rank each measure into five equal-sized bands; "
      "segments use R and F only.")
print("Segment counts and summed customer revenue:")
for name in segment_order:
    group = summary[summary.segment == name]
    noun = "customer" if len(group) == 1 else "customers"
    print(f"{name}: {len(group)} {noun}; {group.monetary.sum():.2f} revenue")
print("Limit: simulated orders do not show real buying habits, profit, "
      "or whether a campaign works.")

Real output from running the script with python3:

Simulated data, seed 23
Input: 137 orders, 30 customers; date window ends 2025-01-01
Method: days since last order, order count, and summed order amount; rank each measure into five equal-sized bands; segments use R and F only.
Segment counts and summed customer revenue:
Champions: 4 customers; 2476.75 revenue
Loyal: 3 customers; 1650.41 revenue
Potential Loyalist: 5 customers; 1875.20 revenue
New Customers: 3 customers; 513.68 revenue
Can't Lose Them: 4 customers; 2309.57 revenue
At Risk: 4 customers; 2001.80 revenue
Hibernating: 4 customers; 895.52 revenue
Need Attention: 3 customers; 325.69 revenue
Limit: simulated orders do not show real buying habits, profit, or whether a campaign works.

Result: The run found 4 Champions with 2476.75 in summed revenue, 4 Can't Lose Them with 2309.57, and 4 At Risk with 2001.80. The full count and revenue list is in the output above. The orders are random, so these revenue totals say nothing about real stores. One question to test next: does a welcome note change what New Customers do?

Limit: These are simulated orders. They do not show real buying habits, profit, or whether a campaign works.

What Is RFM Customer Segmentation?

RFM uses time since the last order, order count, and total order value. See the worked example above for a sample score and group report. Recency measures how many days since a customer's last purchase: a customer who bought yesterday may be more likely to buy again than one who last ordered six months ago. Frequency counts total purchases over a given period: repeat buyers may signal loyalty. Monetary sums the total revenue from that customer.

The analysis scores each customer from 1 to 5 on all three dimensions using quintile rankings. A score of 5 means the customer is in the top 20% for that dimension; a score of 1 means they are in the bottom 20%. Segments use the R and F scores only; M is scored and shown but does not set a segment. The result is a customer base classification that maps to marketing actions you can take this week.

Why This Matters for Your Store

Many e-commerce businesses spend most of their marketing budget on acquisition (Meta ads, Google Shopping, influencer partnerships) while treating their existing customer base as a single undifferentiated list.

RFM segmentation shows where your customers sit today. Customers in the At Risk segment were previously frequent buyers who have gone quiet. They already know your product, so a targeted win-back email to this group is a different job from acquiring a new customer. Test it against your own results.

When to Use RFM Segmentation

What Data Do You Need?

You need a CSV with transaction-level records: one row per purchase, not one row per customer. The required columns are a customer identifier (account ID, email, or customer number), a transaction date, and a revenue or amount column. That is it. Three columns.

Where to get the export

How much data

With few customers, each score band holds only a handful of people, so segment assignments are noisy. Shorter windows may miss seasonal buyers; longer windows may dilute recency signals. Choose a window that fits how often your customers buy.

What does not work

If your product is a one-time purchase with no repeat buying opportunity, like furniture or real estate, RFM's frequency dimension adds no signal. Nearly every customer will score F=1. In that case, a simpler recency-monetary ranking is more appropriate. But for apparel, beauty, supplements, pet supplies, food and beverage, home goods, subscription boxes, and most DTC categories, repeat purchasing is common, so there is more for RFM to work with.

Customer Segments

The analysis assigns every customer to a named segment. The segments come from the standard RFM tool's R and F rules. Segments use the R and F scores only; M is scored and shown but does not set a segment. Each segment suggests an action you could take.

Champions (R4-5, F4-5): Your best customers by recency and frequency. They bought recently and buy often. These are your referral candidates, beta testers, and brand advocates. Consider not discounting to this group, and ask them for reviews and referrals instead.

Loyal (R3, F4-5): Consistent repeat buyers. Reward their loyalty with exclusive access or early product launches.

Potential Loyalist (R4-5, F2-3): Recent customers who have bought a few times. One or two more positive experiences may move them into Loyal territory. Targeted product recommendations and second-purchase incentives are worth testing here.

New Customers (R4-5, F1): One purchase, recently. Welcome sequences, satisfaction surveys, and free shipping on a second order are options to test.

Need Attention (everyone else: R3 with F1-3): Middling recency and frequency. Not in danger yet, but not growing either. A personalized email or a product update announcement can be tried here.

At Risk (R1 with F3, or R2 with F3-5): These customers used to buy fairly often but have gone quiet. They were once valuable and could be again. Win-back campaigns with a clear offer are worth testing, because you already know they bought from you.

Can't Lose Them (R1, F4-5): Frequent buyers who have gone dark. Escalate these first: a phone call, a personal note, or a concession on a past complaint could bring them back.

Hibernating (R1-2, F1-2): Low on recency and frequency. They bought once or twice a while ago and have not returned. Batch email campaigns or lookalike audience exclusions are low-effort options; one-on-one effort here may not pay back.

How to Read the Report

RFM Score Heatmap: The heatmap plots Recency scores on one axis and Frequency on the other, with each cell colored by average Monetary value. Hot cells in the top-right corner (high R, high F, high M) are your Champions. Cold cells in the bottom-left are Hibernating customers. A healthy business has significant mass in the upper-right quadrant. If most of the weight sits in the lower-left, your acquisition funnel is leaking. You are acquiring customers who never come back.

Segment Distribution: The horizontal bar chart shows how many customers fall into each segment. A large share in Hibernating or At Risk points to a retention problem; a large share in Champions and Loyal suggests your retention engine is working. This chart gives you the structural health of your customer portfolio at a glance.

Revenue Treemap: Sizes each rectangle by the segment's total revenue contribution. Champions might be a small share of customers but a large share of revenue. The treemap makes that concentration visible. This is the chart to show your partner or investor when arguing for retention investment. If At Risk and Can't Lose Them together hold a large share of revenue, the case for a win-back campaign is easier to make.

Customer Value Bubble Chart: Positions individual customers by their RFM scores, with bubble size proportional to revenue. It reveals outliers that aggregate views hide. You might spot a single customer with an enormous bubble sitting in the At Risk zone. That is a phone call you need to make today.

Top Customers Table: Ranks top customers by combined RFM score, showing individual R, F, and M scores, segment assignment, and total revenue. This is the tactical output: names or IDs your team can act on immediately. Sort by segment to find your highest-value At Risk accounts or filter to Champions for a referral outreach list.

Segment Summary Table: Aggregates each segment with customer counts, percentage of total, average monetary value, average recency, and average frequency. Run the analysis monthly and track whether your At Risk segment is growing or shrinking. A rising At Risk share over several months is an early warning that something in your product, pricing, or service has changed.

Executive Summary: The AI-generated TL;DR distills the entire analysis into key findings and recommended actions. It highlights revenue concentration risks, flags the most impactful segments, and suggests specific next steps. This is the slide you paste into your Monday meeting deck.

What to Do With the Results

This week

This month

Ongoing

When to Use Something Else

Your turn

Bring your own data and the question you actually need answered.

MCP AnalyticsData science by email Send us your data and your question, and we will reply. ds@mcpanalytics.ai

Working on this for your business? See the RFM segmentation tool.