Converter tool

Customer Lifetime Value from Transactions

Fit BG/NBD and Gamma-Gamma models to a purchase log and get each customer's chance of still being active, expected purchases and discounted lifetime value.

One row per purchase

1. Your data

Or paste the table

Customer Lifetime Value from Transactions

Operator: Abdulla Al Fahad. How tools are built and checked

Customer lifetime value is a forecast, and the forecast depends on a question a purchase log answers only indirectly: is a customer who has not bought for ten weeks gone, or just between orders? A customer who buys every month and has been silent for six is probably gone; one who buys twice a year is not. Probabilistic models answer this from the purchase pattern alone.

This page fits two of them to a transaction file. BG/NBD (Fader, Hardie and Lee, 2005) describes how often each customer buys and when they drop out for good. Gamma-Gamma (Fader and Hardie, 2013) describes how much they spend per purchase. Both are fitted by maximum likelihood. For every customer it gives the probability of still being active, the expected number of purchases over a horizon you choose, expected spend per purchase and a discounted value. A holdout check compares predicted and actual purchases on a period the models never saw.

Key features

  • Purchase log to customer summary: repeat purchases, recency, age and average spend, with same-day orders merged and refunds left out
  • BG/NBD and Gamma-Gamma fits with standard errors, log-likelihood, and warnings for parameters that run to a boundary or fail to converge
  • P(alive), expected purchases and expected spend per purchase for each customer, and a CLV for a horizon of 1 to 60 months with a yearly discount rate and a profit margin
  • A calibration chart of actual against predicted holdout purchases, by number of repeat purchases in calibration
  • Value tiers by CLV rank, a flag for valuable customers who may have lapsed, and a CSV with one row per customer

How the log is summarised, what the two models assume and how CLV is discounted

Each row of the file is one purchase with a customer ID, a date and, for value, an amount. Several purchases by one customer on the same day count as one purchase with the amounts added, because the models count purchase occasions. Negative amounts are treated as refunds and skipped; a zero amount still counts as a purchase. Compact dates such as 19970101 are read, and slash dates follow the order you choose.

The first purchase starts a customer's clock and is not a repeat. Frequency x is the number of repeat purchases up to the calibration end, recency t_x is the time from the first purchase to the last repeat, and age T is the time from the first purchase to the calibration end. Average spend is the mean of the repeat purchases only, and a customer with no repeat purchase has none.

Calibration ends at the date you give, or at the last date in the file if you leave it blank. Purchases after that and up to the holdout end are held out for the calibration chart; without a holdout date there is no chart. Customers whose first purchase falls after the calibration end are not modelled.

Time can be measured in days, weeks or months of 30.44 days; the fitted alpha is in that unit. Up to 100,000 customers and 300,000 rows are accepted.

How it works

BG/NBD assumes each active customer buys at random with a rate that varies between customers as a gamma distribution (shape r, scale alpha), and that after any purchase they drop out with a probability that varies as a beta distribution (a and b). The likelihood for a customer depends only on x, t_x and T, so the page collapses customers with identical triples and maximises the summed log-likelihood over the four parameters on a log scale, using a simplex search from three starting points, each restarted once from where it stopped.

Gamma-Gamma assumes each customer's purchase amount varies around a personal mean with a gamma distribution, and that the personal means follow a gamma distribution too, independent of how often they buy. Expected spend for a customer is a weighted blend of the population mean and their own average, weighted by how many purchases that average rests on. It needs q above 1; otherwise no mean exists and CLV is not computed. The page checks the independence assumption by reporting the correlation between frequency and average spend.

CLV adds up, for each period of the horizon, the expected purchases in that period times expected spend times margin, discounted at the end of the period. The yearly rate is converted to a monthly one as (1 + rate) to the power 1/12 minus 1. Expected purchases in a future window for a customer with a known history use the conditional expectation of the BG/NBD paper, which includes a Gauss hypergeometric function. The page evaluates it after Euler's transformation, whose parameters do not depend on a customer's purchase count, so a customer with hundreds of repeat purchases is scored like any other instead of overflowing.

Common use cases

  • An e-commerce analyst with 80,000 customers ranks them by 12-month CLV to choose the top decile for a retention offer.
  • A subscription box owner finds 150 customers with high CLV but P(alive) under 50% and sends them a win-back message.
  • A finance lead compares the predicted holdout purchases of the last year with the actual figures to decide whether the model can be used for budgeting.
  • A student reproduces the textbook CDNOW analysis from the raw purchase file.

How to use this tool

  1. Drop the purchase log, or load the simulated one that fills in every setting.
  2. Check the customer, date and amount columns, the slash-date order and the time unit.
  3. Enter the calibration end and, for the check, the holdout end.
  4. Set the horizon in months, the yearly discount rate and the profit margin.
  5. Choose Fit the models and wait for the fit; cancel if it takes too long.
  6. Read the parameters, the warnings and the calibration chart before the CLV numbers.
  7. Download the customers CSV.

Example

First rows of the simulated purchase log (600 customers and 1,693 purchases in all) and the settings it loads

customer_id,order_date,amount
C0001,2023-05-29,21.98
C0001,2023-06-01,21.15
C0002,2023-01-04,29.07
(1,690 more rows)
Unit weeks, calibration ends 2024-01-01, holdout ends 2024-12-29, horizon 12 months, discount 10% a year, margin 100%

Fit to all 1,693 purchases

10 same-day purchases merged; 361 of the 600 customers have no repeat purchase in calibration
BG/NBD: r 0.2283, alpha 4.663 weeks, a 1.068, b 3.914; log-likelihood -2,621.0
Gamma-Gamma: p 4.954, q 5.179, gamma 22.21
Calibration, customers with 0 repeats: 0.23 purchases actual against 0.24 predicted; with 7 or more: 6.06 against 5.91
Total 12-month CLV 11,667, largest single value 526, median 7

Tips for best results

  • Use a calibration window long enough to see repeat behaviour: a few months of a business whose customers buy yearly will give almost no repeat purchases and an unstable fit.
  • Compare the calibration chart's actual and predicted bars before you trust a CLV total; large gaps for the 0 and 1 repeat groups mean the dropout part of the model is off.
  • Use weeks for a business with weekly rhythm and months for one that buys monthly; the fit is similar, and the unit only changes how alpha reads.
  • The Top 50 table's Flag column marks customers with at least two repeat purchases and P(alive) below 50%; they are often the best win-back list.

Common pitfalls

BG/NBD fits a non-contractual setting: customers can leave without telling you. For subscriptions with a known end date, use the churn and retention tools instead.

The models assume purchase rates and dropout do not change over time. Seasonality, promotions and a changing product mix break that assumption and show up as a poor calibration chart.

CLV here is revenue times margin, not profit after acquisition cost. It also has no per-customer margin, so a customer who buys low-margin items is valued like one who buys high-margin ones.

Gamma-Gamma assumes spend per purchase is independent of the number of purchases. If frequent buyers spend differently, the page warns when the correlation exceeds 0.3 in size.

Common errors and how to fix them

The file has more than 100,000 customers, which is the limit for the fit.
Fit on a random sample of customers, or on those whose first purchase fell in one cohort period.
The spend model needs at least 10 customers with a repeat purchase and a positive average amount.
Extend the calibration window or use a larger file; with fewer repeat buyers, the page still fits the purchase model.
The calibration end date is before the first purchase in the file.
Enter a date after the first purchase, or leave the field blank to use the last date in the file.
The holdout end date must be after the calibration end date.
Enter a holdout end that falls after the calibration end, or clear the holdout field.

Best practices

  • Fit on one cohort at a time if customers joined in very different periods, such as before and after a pricing change.
  • Keep the holdout as long as the horizon you plan to forecast, so the chart tests the same kind of prediction.

What a parameter hitting a boundary means

Sometimes the best-fitting value of a parameter is zero or infinity, which means the data cannot pin it down: with few repeat purchases, a and b can drift to very large values together or one of them towards zero. The page reports this as a warning with the parameter's name, and shows standard errors only when the curvature at the optimum can be inverted. Treat a fit with either warning as a first look, not as an estimate.

Reading P(alive)

A customer with no repeat purchase has P(alive) of 1 by the model's definition, because there is no evidence of dropout. For customers with repeat purchases it falls the longer they have been silent relative to their usual gap: the formula uses the ratio of (alpha + T) to (alpha + t_x), raised to the power r + x. A customer with 5 repeat purchases that last bought long ago has a P(alive) much lower than one with a single repeat purchase and the same silence.

Frequently asked questions

Does the fit reproduce the published CDNOW parameters?

Fitted to the CDNOW sample (2,357 customers, 39 weeks of calibration, from Fader and Hardie's data) rebuilt from the raw purchase file, the BG/NBD model gives r 0.2426, alpha 4.4136, a 0.7929, b 2.4259 and log-likelihood -9,582.4 against the published 0.243, 4.414, 0.793, 2.426. The Gamma-Gamma fit gives p 6.25, q 3.74 and gamma 15.44, matching the published 6.25, 3.74 and 15.44. The conditional expectation of purchases was also checked against a Monte Carlo simulation of the model and agreed to within 0.002 purchases.

Why is the simulated example's spend model so different from the values used to generate it?

The example was generated with p 6, q 4 and gamma 15, and the fit returns 4.95, 5.18 and 22.2. With 600 customers and only a minority with repeat purchases, the spend parameters are weakly identified; the implied mean spend per purchase, 26.3 against 30, is much closer than the individual parameters.

What is a reasonable CLV horizon?

A year or two for most retail data. Over a longer horizon the forecast leans on the models' assumption of constant behaviour, and the discount rate matters more.

Why are my same-day purchases counted once?

Frequency counts purchase occasions. Splitting one visit into several orders would inflate x and bias the purchase rate upwards, so orders on one date are merged and their amounts added.

Can I use it for B2B accounts?

Only if the accounts buy in a non-contractual, irregular way. Contracted renewals have a known end, which BG/NBD does not use.

When is RFM scoring enough?

When you only need to rank customers by what they did in the past. RFM scores recency, frequency and spend as they stand; this page fits a probability model, so use it when you need purchases and value forecast over a future horizon.