Omniscope Custom Blocks › Analytics/RFM-Segmentation

RFM Segmentation

Scores customers on recency, frequency and monetary value from transactions and assigns named segments such as Champions, At Risk and Lost, with a segment summary.

Analytics › Marketing Python visokio-agents

Open the demo in Omniscope Download demo.ioz Sample data: online-orders.csv Source on GitHub

Items tagged visokio-agents are community examples built by Visokio's agents, to extend Omniscope's core blocks and views with popular, specialist and more unusual use cases, and to show what anyone, people or agents, can build on Omniscope. They are tested by automated tests and were run on a real Omniscope server. They were not reviewed by Omniscope's core team, so they are not on a par with the core blocks and views, which have years of manual, functional and unit tests behind them. About

Omniscope custom block · Analytics

From raw orders to named customer segments in one block: Champions, Loyal, At Risk, Lost and six more, each with recency, frequency and spend scores and a suggested action.

Python · pandas, numpy · nothing extra to install

The problem it solves

CRM and e-commerce teams want to know who their best customers are, who is drifting away and who is already gone. RFM (recency, frequency, monetary value) is a common first answer, but building it means aggregating orders per customer, computing percentile scores, combining them and mapping them to segments, typically a chain of several blocks.

RFM Segmentation does all of it from the transactions table, and adds a segment summary that shows where the revenue sits and what to do about each group.

How it works

What goes in

Online orders (one row per order)

2,879 synthetic orders from 600 customers over two years.

Order ID Customer ID Order Date Order Value
ORD-001498 CUS-0319 2023-11-01 68.78
ORD-002485 CUS-0527 2023-11-01 111.63
ORD-000655 CUS-0144 2023-11-01 46.92
ORD-001370 CUS-0292 2023-11-02 20.9
ORD-002191 CUS-0463 2023-11-02 216.49
ORD-000766 CUS-0167 2023-11-02 153.15

2,879 rows in the sample file.

The options

Option Demo setting What it does
Customer field Customer ID Identifies a customer.
Order date field Order Date Date of each order, for recency.
Order value field Order Value Value of each order, summed for the monetary score.
Order ID field (optional) Order ID Frequency counts distinct order IDs. Leave empty to count rows (one row per order).
Score bands 5 5 gives scores 1 to 5 (quintiles).
Analysis date (empty: day after last order) Recency is measured to this date, such as 2025-12-31. Leave empty for the day after the latest transaction.

What comes out

Customer scores (top customer of each segment)

Customer ID Recency (days) Frequency Monetary R Score F Score M Score RFM Score Segment
CUS-0575 29 15 908.34 5 5 5 555 Champions
CUS-0304 280 10 1,523.60 3 5 5 355 Loyal Customers
CUS-0425 422 15 1,698.05 2 5 5 255 At Risk
CUS-0474 26 2 146.05 5 3 3 533 Potential Loyalists
CUS-0390 484 11 1,437.56 1 5 5 155 Can't Lose Them
CUS-0186 269 2 124.81 3 3 3 333 Need Attention
CUS-0459 7 1 79.61 5 1 3 513 New Customers
CUS-0581 397 1 88.43 2 1 3 213 Hibernating
CUS-0362 328 1 38.42 3 1 2 312 About to Sleep
CUS-0426 515 1 87.56 1 1 3 113 Lost

Segment summary

Segment Customers Share Of Customers Share Of Revenue Average Recency (days) Average Frequency Average Monetary Suggested Action
Champions 139 0.232 0.546 42.45 11.56 790.33 Reward them; early access, referrals, reviews.
Loyal Customers 61 0.102 0.123 236.43 5.574 406.24 Upsell and loyalty schemes; ask for feedback.
Potential Loyalists 53 0.088 0.025 61.15 2.264 96.34 Membership or loyalty offers; recommend related products.
New Customers 48 0.08 0.014 22.79 1 56.92 Onboarding, welcome series, second-purchase incentive.
Need Attention 42 0.07 0.021 247.81 2.5 100.71 Limited-time offers based on past purchases.
About to Sleep 17 0.028 0.003 313.94 1 32.77 Reactivate with popular products and reminders.
At Risk 54 0.09 0.193 388.20 7.167 717.17 Personal win-back campaign; find out what changed.
Can't Lose Them 8 0.013 0.044 487.62 9.625 1,114.38 Win them back with your best offer; talk to them.
Hibernating 65 0.108 0.011 400.02 1 33.57 Low-cost reactivation; otherwise do not over-invest.
Lost 113 0.188 0.02 586.61 1 35.7 Exclude from expensive campaigns; occasional reactivation.
Champions are under a quarter of customers but over half of revenue; At Risk customers still hold a fifth of it (synthetic data).
Champions are under a quarter of customers but over half of revenue; At Risk customers still hold a fifth of it (synthetic data).

Champions are under a quarter of customers but over half of revenue; At Risk customers still hold a fifth of it (synthetic data).

The recency / frequency grid behind the segments: each cell is the share of customers.
The recency / frequency grid behind the segments: each cell is the share of customers.

The recency / frequency grid behind the segments: each cell is the share of customers.

Where it pays off

E-commerce and retail: Lifecycle campaigns

Send win-back offers to At Risk and Can't Lose Them, onboarding journeys to New Customers and VIP perks to Champions, refreshed every week from the order feed.

Subscription and SaaS: Churn early warning

Score accounts on recency of activity or renewal, frequency of use and revenue to find high-value accounts going quiet before they cancel.

B2B distribution: Account prioritisation

Give sales teams a ranked list per territory: Champions to protect, At Risk accounts to call this week, Hibernating ones to hand to marketing.

Charities and membership: Donor segmentation

Apply RFM to donations to time appeals, upgrade regular givers and re-engage lapsed supporters.

Use cases describe typical scenarios and are illustrative.

Why do this in Omniscope

How it fits into an Omniscope workflow

Orders (Database) → RFM Segmentation → Join (customer details) → Report / Email output

Feed it the order lines straight from the database. Join the customer scores back to customer details for contact lists, or to the orders for segment-level trend charts.

Schedule the workflow so segments refresh automatically; to track movement between segments month by month, keep each run's customer scores (for example by appending them to a database table).

In one step

The whole RFM workflow, with the scores exposed so analysts can still define their own segments.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): two years of online orders, one row per order.
  2. The question: who are our best customers, and who should get a win-back campaign this week?
  3. Open RFM Segmentation: customer, date, value and order ID. Nothing else to set. Run it.
  4. Look at the segment summary: Champions are 23% of customers and 55% of revenue; 54 At Risk customers still hold 19% of revenue.
  5. Look at the customer scores and note the suggested action per segment: ready for an export to the email platform.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the sample data, the block, and a Validate data check on its output.

Language and libraries

Python. It uses pandas and numpy, plus the Python standard library (math).

pandas and numpy are part of Omniscope's Docker Python image, and the block was run in both host mode and Docker mode on an Omniscope server, with the same results. It needs nothing else installed.

Tested

On an Omniscope server the demo workflow ran cleanly: 600 records in Customer scores and 10 in Segment summary. The automated tests check normal data, empty input, wrong types and large input.

Reference

Fields it reads

NameTypeWhat it does
Customer fieldFieldIdentifies a customer.
Order date fieldFieldDate of each order, for recency.
Order value fieldFieldValue of each order, summed for the monetary score.
Order ID field (optional)FieldFrequency counts distinct order IDs. Leave empty to count rows (one row per order).

Options

NameTypeWhat it does
Analysis dateTextRecency is measured to this date, such as 2025-12-31. Leave empty for the day after the latest transaction.
Score bandsWhole number5 gives scores 1 to 5 (quintiles).
Text dates are day firstYes / noRead 03/04/2025 as 3 April.

Outputs

OutputWhat it holds
CustomersOne row per customer: recency, frequency, monetary, average order value, R / F / M scores, RFM score, segment.
SegmentsOne row per segment: customers, revenue, shares, averages, description, suggested action.