You have a list of customers and a pile of transactions. Some customers bought yesterday, some six months ago. Some have purchased a dozen times, others once. Some spend generously, others stick to the minimum. RFM segmentation scores every customer on three dimensions (Recency, Frequency, and Monetary value) and groups them into named segments like Champions, Loyal, At Risk, and Hibernating. Upload your transaction CSV and get a segmented customer base.
Worked Example (Simulated)
Question: Which customers score high on recency, repeat orders, and spend in this sample?
Inputs: Simulated order rows with a customer ID, order date, and order amount. The analysis date is fixed in the script. Amounts are integer units, not a named currency. The orders are random draws, made up for this page.
Method: The script makes simulated orders with a fixed seed. It sums orders and spend for each customer, then ranks each measure into five bands. A lower day count since the last order gets a higher recency score. For this example only, a customer is "High on recency and frequency" when both scores are 4 or 5. All others are "Other." This is a simple example rule, not the page tool's segment map.
import numpy as np
import pandas as pd
SEED = 23
rng = np.random.default_rng(SEED)
customer_ids = [f"C{i:02d}" for i in range(1, 21)]
analysis_day = pd.Timestamp("2025-01-01")
rows = []
for customer_id in customer_ids:
order_count = int(rng.integers(1, 9))
days_ago = rng.choice(np.arange(1, 366), size=order_count, replace=False)
amounts = rng.integers(20, 201, size=order_count)
for day, amount in zip(days_ago, amounts):
rows.append((customer_id, analysis_day - pd.Timedelta(days=int(day)),
int(amount)))
orders = pd.DataFrame(rows, columns=["customer", "date", "amount"])
rfm = orders.groupby("customer").agg(
recency=("date", lambda dates: int((analysis_day - dates.max()).days)),
frequency=("date", "size"),
monetary=("amount", "sum"),
)
def band(series):
ranks = series.rank(method="first", ascending=True)
return ranks.apply(lambda rank: int(np.ceil(rank / len(series) * 5)))
# Smallest recency is best; higher frequency and spend are best.
rfm["R"] = 6 - band(rfm["recency"])
rfm["F"] = band(rfm["frequency"])
rfm["M"] = band(rfm["monetary"])
# Illustration only: recency and frequency scores of 4 or 5 form one group.
rfm["group"] = np.where(
(rfm[["R", "F"]] >= 4).all(axis=1), "High on recency and frequency", "Other"
)
high_all_three = int((rfm[["R", "F", "M"]] >= 4).all(axis=1).sum())
fm_corr = rfm["frequency"].corr(rfm["monetary"], method="spearman")
print(f"Simulated data, seed {SEED}")
print(f"Analysis date: {analysis_day.date()}")
print(f"Customers: {len(rfm)}; orders: {len(orders)}")
print("Inputs: customer ID, order date, order amount (integer units)")
print("Scores: five equal-count bands; R reverses recency (fewer days = higher).")
print("Illustrative groups: R and F both 4-5, or Other.")
print("Group counts:")
names = ["High on recency and frequency", "Other"]
print(rfm["group"].value_counts().reindex(names, fill_value=0).to_string())
print(f"Also high on M (4-5) as well: {high_all_three} customers")
print(f"Spearman correlation, frequency vs monetary: {fm_corr:.2f}")
print("First five customers (recency days, frequency, monetary, R, F, M, group):")
cols = ["recency", "frequency", "monetary", "R", "F", "M", "group"]
print(rfm[cols].head().to_string())
Printed output:
Simulated data, seed 23
Analysis date: 2025-01-01
Customers: 20; orders: 80
Inputs: customer ID, order date, order amount (integer units)
Scores: five equal-count bands; R reverses recency (fewer days = higher).
Illustrative groups: R and F both 4-5, or Other.
Group counts:
group
High on recency and frequency 6
Other 14
Also high on M (4-5) as well: 6 customers
Spearman correlation, frequency vs monetary: 0.95
First five customers (recency days, frequency, monetary, R, F, M, group):
recency frequency monetary R F M group
customer
C01 254 1 96 1 1 1 Other
C02 42 6 653 3 4 4 Other
C03 24 4 231 3 2 2 Other
C04 17 5 693 4 4 5 High on recency and frequency
C05 343 1 104 1 1 1 Other
Result: 6 of 20 customers have recency and frequency scores of 4 or 5, and all 6 also score 4 or 5 on spend. Spend here is the sum of order amounts, so it follows frequency (rank correlation 0.95); in this sample spend adds no separate grouping.
Limit: These made-up orders cannot show how real buyers act or whether a campaign works.
What Is RFM Segmentation?
RFM looks at when a customer last bought, how often they bought, and how much they spent (Recency, Frequency, and Monetary). See the simulated example above. Each dimension captures a different facet of customer behavior. Recency measures how recently a customer last purchased: a customer who bought yesterday is more engaged than one who last bought six months ago. Frequency counts how many times the customer has purchased over a given period, repeat buyers signal loyalty. Monetary sums the total revenue from that customer: high spenders are more valuable per acquisition dollar.
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%. The analysis places each customer in a named segment using their recency and frequency scores, from Champions (high recency and frequency) to Hibernating (low recency and frequency). The result is a customer base classification you can match to marketing actions.
Customer Segments
The analysis places each customer in a named segment using their recency and frequency scores. Each score pair falls in exactly one segment. Each segment suggests a business action to consider:
Champions (R4-5, F4-5): Customers who bought recently and buy often. These are referral candidates, beta testers and brand advocates. Test whether they need a discount at all, since they are already buying.
Loyal (R3, F4-5): Customers who buy often, though not always as recently as Champions. 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 good experiences may move them toward Loyal. Onboarding sequences and personalized recommendations are options to test.
New Customers (R4-5, F1): Just arrived, with one recent purchase. Welcome sequences, satisfaction surveys and second-purchase incentives are options to test.
Need Attention (every score pair the other segments do not cover): Customers in the middle. A nudge, such as a personalized email or a product update, is one option to test.
At Risk (R1 with F3, or R2 with F3-5): These customers used to buy often but have not bought recently. A win-back offer may be one option to test with this group. Compare its cost and results with other campaign options before choosing an approach.
Can't Lose Them (R1, F4-5): Customers who bought often but have not bought for a long time. Consider a personal contact from customer success or the founder, and check the cost against what these accounts are worth.
Hibernating (R1-2, F1-2): Customers who bought rarely and not recently. Batch email campaigns or lookalike audience exclusions are low-effort options; one-on-one effort here may not pay off.
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, customer number), a transaction date, and a revenue or amount column. Optional columns include invoice or order ID and unit cost or quantity if you want the tool to calculate revenue from components.
The analysis needs at least 50 unique customers and 100 total transactions for meaningful segmentation. With fewer customers, the quintile boundaries become unreliable. Each quintile would contain fewer than 10 customers, making segment assignments noisy. For best results, use 6 to 12 months of transaction history with 200 or more customers. Shorter windows can miss seasonal buyers; longer windows can dilute recency signals.
The data should reflect repeat-purchase behavior. If your product is a one-time purchase (like a house or a car), RFM's frequency dimension will not be informative, nearly every customer will score F=1. In that case, a simpler recency-based ranking or a CLV model is a better fit. But for e-commerce, SaaS billing, subscription boxes, restaurant loyalty programs, B2B supplies, and most retail businesses, RFM fits because repeat purchasing is the norm.
How to Read the Report
RFM Score Heatmap
The heatmap is the centerpiece of the report. It plots Recency scores on one axis and Frequency scores on the other, with each cell colored by average Monetary value. Hot cells in the top-right corner (high R, high F, high average M) are where Champions sit. Cold cells in the bottom-left are your Hibernating customers. The heatmap instantly shows whether your customer base is concentrated in healthy territory or skewing toward disengagement. A business in good health will have significant mass in the upper-right quadrant. A business with a retention problem will see heavy weight in the lower-left.
Customer Segment Distribution
The horizontal bar chart shows how many customers fall into each segment. A reasonable spread across segments is a sign of a balanced base; a base dominated by Hibernating customers points to a retention problem. Compare the shares with your own earlier runs. This chart gives you the structural health of your customer portfolio at a glance.
Customer Value Map (Bubble Chart)
The scatter plot positions individual customers by their RFM scores, with bubble size proportional to revenue. It reveals outliers that aggregate views can 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, not next quarter. The bubble chart also shows how tightly or loosely your customers cluster, which suggests whether your segments are well-separated or blurry.
Revenue Treemap by Segment
The treemap sizes each rectangle by the segment's total revenue contribution. A small share of customers can account for a large share of revenue. The treemap makes that concentration visible. This is the chart to show your CFO when arguing for retention investment. If At Risk and Can't Lose Them together hold a large share of revenue, that supports a win-back campaign.
Top Customers Table
The table ranks the top 20 customers by combined RFM score, showing their individual R, F, and M scores, segment assignment, and total revenue. This is the tactical output: names (or IDs) your sales team can act on immediately. Sort by segment to find your highest-value At Risk accounts, or filter to Champions to build a referral outreach list.
Segment Summary Table
The summary table aggregates each segment with customer counts, percentage of total, average monetary value, average recency, and average frequency. This is where you set benchmarks. Run the analysis monthly and track whether your At Risk segment is growing or shrinking. A growing At Risk share over several months is a prompt to check what changed in your product, pricing, or service.
Executive Summary
The TL;DR slide distills the entire analysis into key findings and recommendations generated by AI. It highlights the largest segments, flags revenue concentration risks, and suggests specific actions for the most impactful segments. This is the slide you paste into your Monday leadership meeting deck: one page that answers "how healthy is our customer base right now?"
When to Use Something Else
If you need to predict which specific customers will churn (not just flag who is at risk), a logistic regression or survival analysis model gives you explicit probabilities per customer. RFM tells you who is at risk today; predictive models tell you who will be at risk next month.
If your customer data has more than three behavioral dimensions: page views, support tickets, feature usage, NPS scores: consider k-means clustering or DBSCAN. These methods can segment on any number of features, while RFM is intentionally constrained to three. That constraint is a strength for simplicity and interpretability, but a limitation when you have richer data.
If your business model involves one-time purchases with no repeat buying opportunity, RFM's frequency dimension adds no signal. A simple recency-based ranking combined with monetary value (an "RM" analysis) is more appropriate. Alternatively, if you have contractual subscription data with fixed billing cycles, frequency is artificially uniform and the F-score will not differentiate customers: use engagement metrics instead.
For a conceptual guide to RFM methodology and manual implementation, see our RFM practical guide. This module automates the entire workflow (scoring, segmentation, visualization, and interpretation) so you can focus on action rather than calculation.
The R Code Behind the Analysis
Every report names its method and includes the R code that produced it, so you can reproduce, audit and cite it. The method code is fixed, not rewritten for each run, so the same data gives the same analysis every time.
The analysis calculates recency as days since last purchase, frequency as total transaction count per customer, and monetary value as total revenue per customer. Quintile scoring uses ntile() from dplyr to assign 1-5 scores on each dimension. Segment assignment follows a rule-based mapping from the recency and frequency scores to named segments. Visualizations use ggplot2 for the heatmap, treemap, and bubble chart. Every step is visible in the code tab of your report, so you or an analyst can check exactly what was done and reproduce it outside the platform if needed.
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