The business problem
An online retailer has millions of customers and tens of thousands of products. Every month it decides whom to send an offer to, which customers to try to win back, and what to show each one.
Each of these decisions rests on a prediction about a customer. Will they stop buying? How much will they spend? What will they buy next?
What makes it hard
- The data is spread across tables. Customers, orders, order lines, products, reviews and returns sit in separate tables, joined by keys.
- What matters is often a few joins away. Whether a customer's last order was returned, or whether the products they buy are being dropped from the range, sits two or three tables away from the customer.
- Most customers have few orders. A large share of customers have bought once or twice. There is little of their own history to go on.
- Spend is lumpy. Many customers spend nothing in a given month, and a few spend a lot.
- Churn has no clear date. Customers rarely close an account. They just stop buying, so churn has to be defined over a window.
The data a retailer usually has
All of it sits in the order database, which most retailers already keep in a warehouse.
| Table | Example | When it is known |
|---|---|---|
| Customers | Sign-up date, region, channel | At sign-up, updated rarely |
| Orders | Order date, total, payment method, discount used | When the order is placed |
| Order lines | Product, quantity, price | When the order is placed |
| Products | Category, brand, price, description | Fixed, with price changes |
| Reviews | Rating and text | When the review is written |
| Returns | Product returned and the reason | Days or weeks after the order |
How it is solved today
The usual approach is a feature table and a boosted tree model for each question.
- An analyst defines the question, such as no order in the next 90 days, and picks a set of past dates to learn from.
- For each customer and date, the tables are joined and rolled up into one row: orders in the last 30, 90 and 365 days, total spend, days since the last order, share of orders with a discount, favourite category, and so on. A mature feature table has hundreds of columns.
- A boosted tree model is trained on that table. Churn, spend and next purchase each get their own feature table and model.
- Next-purchase recommendations come from a separate system, such as collaborative filtering.
- When the business adds a table, such as returns or app visits, the feature work starts again.
Where it falls short
- Rolling up a customer's orders into counts and averages loses which products were bought, and in what order.
- Signals that sit several joins away, such as the return rate of the products a customer buys, are used only if someone thinks of them and builds them.
- Customers with one or two orders get rows that are mostly zeros.
- Each question needs its own feature table, model and maintenance.
- A rolling window built at the wrong date leaks future orders into the past. Such leaks are easy to make and hard to find.
How tabSutra solves it
The database goes in as it is
You send the tables and say how they are joined. You describe the question, for example the total spend of each customer in the next 30 days, and the date to stand at. tabSutra builds the past examples from the database itself and predicts for each customer.
Your tables
| Table | Rows | Joined by |
|---|---|---|
| Customers | 1.2M | customer |
| Orders | 9.8M | customer |
| Order lines | 31M | order, product |
| Products | 64k | product |
| Reviews | 2.1M | customer, product |
Each table as it is, with its keys.
tabSutra
- Follows the keys from each customer to their orders, products and reviews
- Reads each table as it stood on the date of the prediction
- Answers churn, spend and next purchase with the same model
- Builds the past examples from the database, with no leakage
Next 30 days, as of 1 December
| Customer | Churn | Spend, median | Spend, mean |
|---|---|---|---|
| C-10482 | 0.12 | $64 | $81 |
| C-22719 | 0.71 | $0 | $9 |
| C-30155 New | 0.38 | $18 | $33 |
Plus a ranked list of the products each customer is likely to buy.
Why flattening loses signal
A feature table gives each customer one row. Everything about their orders, the products in them and the reviews they wrote has to be squeezed into numbers on that row.
Take two customers who each placed four orders worth $200 in the last year. In the feature table they look the same. In the database, one bought from categories that are growing and rated the products highly. The other bought products that were later dropped from the range, and returned two of them. The second customer is far more likely to leave.
tabSutra follows the keys from each customer to their orders, to the products in them, and to the other customers who bought the same products. It reads directly the signal that a feature table drops.
New and occasional customers
A customer with one order has almost nothing of their own to go on. In a feature table, most of their columns are zero.
tabSutra reads what that one order tells it: what was bought, at what price, with what discount, and how other buyers of the same products behaved afterwards. A new customer is compared with customers who started the same way.
Spend, and what to buy next
Many customers spend nothing in a given month, and a few spend a lot. So the median of a customer's predicted spend is often zero, while the mean is above it. Use the mean for totals, such as a revenue forecast for a region, because means add up and medians do not. Use the range to see how uncertain one customer's spend is.
The same model ranks the products each customer is likely to buy next, with a probability for each.
In some businesses, such as groceries, people mostly buy the same things again, and a simple rule that repeats past purchases is hard to beat. In others, such as fashion or books, people rarely buy the same item twice. Comparing with that rule on your own data shows which kind of business you are in.
Public data with the same shape
These public datasets have the same shape as the problem. They are listed so that the approach can be checked on open data.
| Dataset | Source | What it tests |
|---|---|---|
| rel-amazon: user churn, user lifetime value | RelBench | Churn and spend of an online store's customers, from customers, products and reviews |
| rel-amazon: item churn, item lifetime value | RelBench | Which products will stop selling, and how much each will sell |
| rel-amazon: user-item purchase | RelBench | Which products each customer will buy next |
| rel-hm: user churn, item sales | RelBench | Churn and article sales for a fashion retailer, from customers, articles and transactions |
| rel-hm: user-item purchase | RelBench | Next purchases in fashion, where repeat purchases are rare |
RelBench reports results for boosted trees on a flat feature table, which is the comparison that matters here. Customers with one or two orders can be scored as a separate group, to test the new-customer case.
Side by side
Feature table compared with tabSutra
| Feature table with boosted trees | tabSutra | |
|---|---|---|
| Work before the first prediction | Joins, roll-ups and a feature table for each question | The tables, and a description of the question |
| Signals several joins away | Used only if someone builds a feature for them | Read by following the keys |
| Order and product detail | Rolled up into counts and averages | Kept |
| New and occasional customers | Rows of mostly zeros | Compared with customers who started the same way |
| Churn, spend and next purchase | Three feature tables and models, plus a recommender | One model |
| A new table, such as returns | The feature work starts again | The table and its keys are added |
| Leakage from wrong dates | Easy to make, hard to find | Each table read as it stood on the date |
Benefits
What the business gets
Answers in hours
A new question is described, not engineered. The first answer does not wait for a feature table.
More signal from the same data
Products, returns and reviews several joins away are read, not dropped.
New customers covered
Customers with one or two orders get predictions based on how similar customers behaved.
One model for every customer question
Churn, spend and next purchase come from the same model, on the same database.
Totals that add up
Each customer has a mean and a range, so regional and campaign totals can be built from them.
No leakage by construction
Every prediction uses the tables as they stood on its date.
Questions
Do we need to build a feature table?
No. You send the tables and their keys, and describe the question. tabSutra builds the past examples from the database at the dates you choose.
How do we define churn?
As no order within a window you choose, such as 30 days for groceries or a year for furniture. The definition matters more than the model. It is worth trying a few windows and looking at what each one predicts.
Can we check it on past data?
Yes. Stand at a past date, predict, and compare the predictions with what happened afterwards. The model uses only what was known on that date.
Can it read text, such as reviews?
Yes. Review text and product descriptions are read as text columns, next to the ratings and prices.
How is our data handled?
Your rows are used only to answer your request. They are not used to train the model. A context you send is kept for a limited time, so that you can predict again without sending it, and you can delete it at any time.
Ask your order database a question
API access is open to teams on request. The documentation has a worked example for churn, spend and next purchase on a retail database.