Customer analytics · real data

Who are the best customers, who is leaving, and what are they worth?

A UK-based online retailer of gifts and homewares: 1.07 million invoice lines from December 2009 to December 2011. Every answer here was checked against what actually happened next.

The business

Four questions a CRM team asks

1

Who are the best customers?

2

Who is leaving?

3

Is retention improving?

4

What is each customer worth?

Product sales by month: the peak repeats every September to November

About 13% of sales has no customer ID: real revenue, but it cannot be attributed to anyone.

Data quality

Measured before cleaning

The file has 34,335 lines identical to another line. The reflex is drop_duplicates(). Measuring first showed two different things.

0

Removed: an export artefact

The two Excel sheets overlap from 1 to 9 Dec 2010, identical line for line. Kept once, December stops counting twice.

0

Kept: they look like real purchases

86% sit on non-adjacent lines of the same invoice, and the same product often comes back with another quantity: an item added twice to an order. Deleting them would remove real sales.

How it is built

The SQL does the maths, Python orchestrates

↓
DownloadUCI file, SHA-256 checked
1
brutoraw, as text
2
limpotyped, CHECK rules
3
analiseRFM, churn, cohorts, CLV
dq
Quality18 checks, roll back on failure
↗
OutputsPower BI, notebook, this page
0

SQL migrations

Every rule is versioned SQL. Functions take a reference date, so validation cannot peek at the future.

0

quality checks

If one fails, the whole run rolls back: a wrong number never reaches the report.

0

automated tests

Hostile inputs, four session time zones and an end-to-end run on the real file.

Question 1 · Who are the best customers?

A quarter of the customers bring 69% of revenue

Recency, frequency and value scored 1 to 5 in SQL, with ties always on the same score, then mapped to ten segments, each with an action for the CRM team.

0%of revenue from the top 10% of customers
0%bought two times or more
Segments and suggested actions
Question 2 · Who is leaving?

A simple rule, tested at a past date

“More than 90 days without buying”, applied on a past date with only what was known that day, then compared with who actually came back in the next six months.

–of flagged customers really did not come back
–of those who left were caught
–caught right after the Sep–Nov peak: many only come back at the next one

Question 2 · Where the rule has signal

Did not come back, by days without buying at the cut-off

Separate “at risk” from “already gone”

Just past 90 days, customers did not come back about as often as the average customer. The rule mostly separates the active from those who left long ago.

0

at risk · 91–365 days

– of revenue in the last 12 months

0

inactive · over a year

Already gone: no recent revenue.

Question 3 · Is retention improving?

About one in five customers buys again the next month

Whether it is improving, two years of data cannot say: early cohorts mix in old customers who came back, and the season moves month 1. A first draft claimed new customers fell 36%; with the same history window for both years it is 979 against 940, so the claim was withdrawn.

Question 4 · What is each customer worth?
–

expected in the next 6 months

Active probability by segment (same season a year earlier) × average order × purchases per month (smoothed) × months. A forecast made on 10 June 2011 was checked against the real revenue to 10 December.

It beats the fair, seasonal baseline on all three measures. The error on the total is partly luck: by segment the bias runs from −17% to +199%, and errors offset.

Forecast vs actual, 6 months after 10 June 2011

Before publishing

Three independent reviews

✓ Every headline number re-queried: none was wrong

QA

Adding six months to a timestamp depended on the session's time zone. Fixed inside every function and tested in four zones.

Data methodology

A false acquisition drop, a churn headline mixing “at risk” with “gone”, and a weak baseline. All rewritten.

Engineering

Failed checks could still be saved and exported. Now the run rolls back and the export refuses.

Thanks for reading.

What I would do next

Churn per customer

A threshold from each customer's own buying rhythm, or a model that sees the season.

Probabilistic CLV

BG/NBD and Gamma-Gamma, compared with this model and the seasonal baseline.

Basket analysis

Which products sell together, to feed each segment's action.

Diego Freitas Santiago · Data Analyst · PostgreSQL, SQL, Python, Power BI

Data: Chen, D. (2012). Online Retail II [Dataset]. UCI Machine Learning Repository, CC BY 4.0.