tabSutra

Case study · E-commerce

Churn, spend and next purchase from an order database

An online retailer wants to know which customers will stop buying, how much each will spend, and what each will buy next. The answers sit in its order database. This page shows how these questions are answered today, and how tabSutra answers them from the database as it is.

IndustryOnline retail, marketplaces and subscription commerce
QuestionWill a customer stop buying? How much will they spend? What will they buy next?
DataCustomers, orders, order lines, products, reviews and returns
OutputA probability, a spend forecast with a range, or a ranked list, for each customer

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.

TableExampleWhen it is known
CustomersSign-up date, region, channelAt sign-up, updated rarely
OrdersOrder date, total, payment method, discount usedWhen the order is placed
Order linesProduct, quantity, priceWhen the order is placed
ProductsCategory, brand, price, descriptionFixed, with price changes
ReviewsRating and textWhen the review is written
ReturnsProduct returned and the reasonDays 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.

  1. An analyst defines the question, such as no order in the next 90 days, and picks a set of past dates to learn from.
  2. 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.
  3. A boosted tree model is trained on that table. Churn, spend and next purchase each get their own feature table and model.
  4. Next-purchase recommendations come from a separate system, such as collaborative filtering.
  5. 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

TableRowsJoined by
Customers1.2Mcustomer
Orders9.8Mcustomer
Order lines31Morder, product
Products64kproduct
Reviews2.1Mcustomer, 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

CustomerChurnSpend, medianSpend, mean
C-104820.12$64$81
C-227190.71$0$9
C-30155 New0.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.

DatasetSourceWhat it tests
rel-amazon: user churn, user lifetime valueRelBenchChurn and spend of an online store's customers, from customers, products and reviews
rel-amazon: item churn, item lifetime valueRelBenchWhich products will stop selling, and how much each will sell
rel-amazon: user-item purchaseRelBenchWhich products each customer will buy next
rel-hm: user churn, item salesRelBenchChurn and article sales for a fashion retailer, from customers, articles and transactions
rel-hm: user-item purchaseRelBenchNext 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 treestabSutra
Work before the first predictionJoins, roll-ups and a feature table for each questionThe tables, and a description of the question
Signals several joins awayUsed only if someone builds a feature for themRead by following the keys
Order and product detailRolled up into counts and averagesKept
New and occasional customersRows of mostly zerosCompared with customers who started the same way
Churn, spend and next purchaseThree feature tables and models, plus a recommenderOne model
A new table, such as returnsThe feature work starts againThe table and its keys are added
Leakage from wrong datesEasy to make, hard to findEach 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.