# Online retail win-back study

Which customers who stopped ordering are worth a win-back contact, how much revenue is at stake, and how much comes back anyway?
A study on real public transactions from a UK online gift-ware retailer that ends in a recommendation, with the cleaning, the
checks, the test to run next and what it is worth.

The data is real and public: Online Retail II from the UCI Machine Learning Repository (Daqing Chen, CC BY 4.0; see
[NOTICE.txt](NOTICE.txt)). It stands in for any business deciding which lapsed customers are worth money to bring back; no
customer data from any employer is used. The study is unaffiliated with the publisher and the retailer.

Open `index.html` in a browser for the full study: who brings the revenue, who came back with no contact, where the lost revenue
sits, what went wrong or was missed, which method to use when, how I would roll the test out with a team, and what it is worth.

## Answer

On 1 June 2011, 330 high-value customers (the top 30% by past-year revenue) had not ordered for three months.
222 of them (67%, bootstrap interval 62% to 72%) ordered again within six months with no contact recorded. The data holds
orders only, so it cannot show whether anyone was contacted.
That list held 38% (31% to 45%) of the past-year revenue of quiet customers who did not come back, below the 50% bar set
before the analysis; the rest sat with about 2,000 smaller customers. The same rule on 1 December 2010 came closer (49%, 40% to 57%):
too close to the bar to call, since it met the bar in 39% of resamples. Fewer came back at that date: 43% of the December
2010 list, so "most big customers came back" holds at the June date only.

Recommendation: do not fund a win-back program aimed at the biggest past spenders. Put a cheap offer in front of a random half
of all 2,358 quiet customers, hold out the other half for six months, and fund the program only if the contacted half's revenue
beats the holdout's by more than the offer costs. That test can detect a rise of about 6 points in the share who come back,
while a test on the 330-customer list alone could only detect about 13 points.

What it is worth (US$ at an assumed US$1.30 per pound, no inflation adjustment; an assumed 40% gross margin, since the data has
no costs): without a holdout, a campaign on the list would be credited with about £359K that arrived anyway (about US$467K).
If a contact brought back 10 more of every 100 customers on the list (an assumption; the data records no campaigns), it would
add about £53K over six months (£42K to £69K from the measured spend of customers who came back with no contact recorded;
£27K at 5 points, £107K at 20 points). At that lift a contact is worth about US$84 of margin per list customer, and about US$42
at a 5-point lift. That US$42 is a base case (5-point lift, 40% margin, June's spend per returner); on December's spend per
returner it is about US$24, so I would cap the offer for high-value customers at US$24 to US$42 until the test sets it, and
offer smaller customers something cheaper.

## What was set in advance

Before any result was computed, the question, the two decision dates, the windows (365 days back, 180 days forward, quiet after
90 days), the value tiers, six measures, the bootstrap settings, the sensitivity runs and the decision rule were written down.
The rule: recommend a value-targeted list only if it holds at least 50% of the revenue that did not come back while being at most
35% of quiet customers. Two additions came after the results and are labelled as exploratory in `results.json`
(`exploratory_after_results`) and on the page: the revenue the list brought back with no contact, and the test size for a holdout
on all quiet customers. The US$ conversion, the margin and the per-contact figures are arithmetic on frozen results with the two
declared assumptions, computed in `render.py` (`derived()`); no new measure was run for them.

## Cleaning, shown and tested

| Step | Lines | Note |
|---|---:|---|
| Source lines in two yearly sheets | 1,067,371 | the sheets overlap by 22,523 identical lines from 1 to 9 December 2010, counted once |
| Exact duplicate lines dropped | 11,812 | a sensitivity run keeps them |
| Product sales | 1,003,214 | £19.64M; 13% of that value has no customer number |
| Cancellations (invoice starts with C) | 17,914 | netted against sales on their own dates |
| Zero or negative quantity or price | 5,928 | excluded |
| Non-product codes (postage, fees, manual entries, discounts) | 5,980 | excluded; 62 codes listed in `data/derived/cleaning.json` |

The three largest sale lines (80,995, 74,215 and 60 units) were each cancelled the same day; netting stops one mistaken order
from ranking a customer first. Each step is a function in `retail/clean.py` with a test in `tests/test_clean.py` on constructed
fixtures whose answers follow from their construction.

## Reproduce

Prerequisites: Linux, Python 3.12.3, uv 0.11.7 and curl. Packages are pinned with hashes in `requirements.lock`.
The source file (45.6 MB) is downloaded from the publisher and checked against its SHA-256 before use.

```sh
uv venv --python python3.12 .venv
uv pip sync --python .venv/bin/python --require-hashes requirements.lock
make download
make all
```

`make all` verifies the download, prepares the cleaned lines (mostly reading the workbook), computes `results.json` and the
customer tables in `data/derived/`, runs the tests and renders `index.html`. To re-render the page and run the tests without
recomputing anything, run `make render test`. Open `index.html` directly or preview with `python3 -m http.server`.
The page shell, fonts and number formatting come from viz-design-system release 2.0.4, copied unedited into
`vendor/viz-design-system/` and pinned in `vendor/viz-design-system-adoption.json`.

## Files

- `retail/clean.py`, `retail/measures.py`: cleaning steps and the declared measures.
- `pipeline.py`: verify, prepare and analyze stages. `render.py`: the page, and the two declared money assumptions.
- `results.json`: every measure at both decision dates, bootstrap intervals (2,000 replicates with a fixed seed), sensitivity runs,
  cleaning counts and the exploratory additions.
- `data/SOURCES`: download URL, licence, size and SHA-256. `data/derived/`: derived tables with hashed customer keys.

## Limits

- One retailer, one market, two years; many customers are wholesalers, so the rates are a starting point for the test.
- The data records orders, not contacts. "Came back" means ordered again with no contact recorded; whether anyone was
  contacted is unknown, and the gain from a contact is an assumption.
- The return rate differed between the two dates: 43% of the December 2010 list came back, against 67% of the June 2011 list.
  That fits the autumn sales peak, but two dates in different years cannot separate season from year.
- The expected effect multiplies an assumed lift by the spend of customers who returned with no contact recorded; customers won back by an
  offer may spend less. Money figures are revenue; the margin is an assumption.
- 13% of sales value has no customer number and cannot enter customer measures.
- The product-code rule also excludes 157 lines of gift-set codes worth about £1.2K.

## Data notice

Read [NOTICE.txt](NOTICE.txt) for the attribution and the changes made. Customer numbers are replaced by a salted SHA-256 key
and product descriptions are not redistributed.

Some files are packed in retail-win-back-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
