Skip to content
Dionysios ZeliosCommercial Growth | B2B SaaS | AI Commercialization | International GTM
Framework

Cohort Analysis and Predicting Customer Value

How to build retention and revenue cohorts from order data, then predict which customers will be valuable from their transaction history.

9 min read · 9 sections

A cohort view turns a long list of orders into a way to compare customer groups over time. Instead of asking only how much was sold this month, you can ask whether customers acquired in different periods return at similar rates, and how their revenue develops as they age. The method begins with a stable customer identifier, a trustworthy first-order date and consistent periods.

A second, complementary question is which customers appear likely to become valuable. Transaction history can be summarised into features and used to train a classifier against a clearly defined future outcome. The resulting score is a prioritisation aid, not a promise: careful timing, evaluation and measured follow-up matter more than model complexity.

Prepare and define the data

Start with one row per order, with at least an order date, customer identifier and charge amount. Confirm that dates parse consistently, amounts are numeric and identifiers are stable across repeat orders. Remove test, cancelled or refunded orders according to a documented rule. If refunds are meaningful, retain them as separate adjustments rather than quietly treating them as purchases. Decide whether charges include tax, shipping or discounts, and use the same definition throughout.

Select a cohort interval suited to the buying cycle. Monthly cohorts are useful for frequent purchases; quarterly or yearly groups may be more stable for infrequent, high-consideration purchases. The acquisition cohort is the interval containing each customer's first observed purchase. “Observed” is important: if the history starts recently, an existing customer's first record can be mistaken for their true first order. Where possible, use a lookback period long enough to detect earlier activity, or label these customers as left-censored.

Build acquisition cohorts

For each customer, find the earliest valid order date. Convert it to the chosen cohort period, then attach that cohort label to every order by that customer. Calculate each customer's age at order time in periods: the cohort month is age zero or month one, depending on your convention. Choose one convention and label axes clearly.

Aggregate distinct active customers by acquisition cohort and age. Divide each period's active customer count by the cohort's starting customer count to obtain retention. Decide what “active” means. An order in a period is a simple definition; a subscription renewal or product-use event may be more appropriate elsewhere. Multiple orders by one person in a period should not inflate customer retention.

From orders to cohorts
  1. 01Clean ordersValidate dates, IDs and charge rules
  2. 02Find first buyAssign each customer an acquisition period
  3. 03Measure ageCount periods since acquisition
  4. 04AggregateCount active customers and sum charges

Read the retention triangle

Place cohort periods down the rows and elapsed periods across columns. The diagonal is each cohort's first period; cells to the right show what happened as the same cohort aged. A triangle forms because newer cohorts have not yet had time to populate later-age columns. Those blank cells mean “not yet observed”, not zero retention. Keep blanks distinct from actual zeroes in both calculations and visualisation.

A steady decline across a row can be normal: customers naturally stop purchasing, and periodic or seasonal demand can create gaps. Compare like-for-like ages rather than comparing the latest cohort's first month with an older cohort's mature period. Read down a column to compare cohorts at the same age. An improvement down a column may signal better acquisition quality or onboarding, but check changes in product mix, pricing, channel, season and data coverage before attributing cause.

Retention ratios can be volatile when the starting cohort is small. Show cohort sizes alongside percentages, combine periods where appropriate and avoid declaring a trend from a thin row. Also consider a rolling activity definition if purchase timing is irregular, such as “at least one order in the last several periods”; state the window because it changes the meaning.

Build and interpret the revenue triangle

Use the same cohort and age structure, but sum charges for orders in each cell. Decide whether the view represents revenue per cohort, per acquired customer or per active customer. These answer different questions. Total cohort revenue naturally favours larger starting cohorts. Revenue per acquired customer divides each cell's revenue by the original cohort size and captures both repeat activity and spend. Revenue per active customer describes spend among those still buying, but can rise even while the cohort shrinks.

Cohort triangle reading guide
Acquisition cohort →

Early diagonal

Starting activity; check cohort size

Later row

Track retention or cumulative value

Same column

Compare cohorts at equal age

Blank future

Not observed yet; never treat as zero

Elapsed period →

A period revenue triangle shows revenue in that period; a cumulative triangle adds prior periods. Label them distinctly. Cumulative revenue should not fall unless adjustments such as refunds are included. Large orders can dominate totals, so pair means with medians or distribution bands where data allow. Report currency and gross-versus-net basis, but do not confuse revenue with margin or lifetime value. Costs to serve, acquisition expense and future uncertainty are absent unless explicitly modelled.

Seasonality is a frequent trap. A cohort acquired just before a peak may look stronger at a given age simply because its second period coincides with a seasonal high. Use enough historical cycles where possible, compare matched calendar periods, or annotate seasonal context. Investigate operational changes and channel composition before making a causal claim.

Engineer transaction-history features

For prediction, define the unit as one customer or merchant and construct features using only transactions available by a specific observation date. Useful summaries include count and sum of payments, average and median amount, time since last payment, time between payments, variability, trend, share of recent activity, and number of active periods. For payment series, consider payment-type proportions and whether activity is accelerating, weakening or concentrated in a few large transactions. Use sensible windows (recent and longer-term) tied to the business cycle.

Aggregate carefully: duplicate rows, reversals and inconsistent currencies can distort totals. Include context such as tenure or broad merchant characteristics only if available at scoring time and permitted. Handle missing values explicitly; “no recent payment” can be meaningful, while missing data may indicate a feed problem. Scale or encode fields as needed by the method, and keep a feature dictionary explaining the definition, time window and data source.

Define the outcome and split fairly

“Profitable” must be operationally defined: for example, whether a customer crosses a contribution threshold during a future horizon. Choose the horizon and label rules with finance and business owners. Do not use lifetime totals from after the observation date as predictors; that leaks the answer into the inputs. Create a snapshot per customer at a cutoff and label what happens afterwards.

Split training and test data so the test set represents genuinely unseen cases. A time-based split is often more realistic: train on earlier snapshots and test on later ones. Keep all snapshots for a customer on one side, or otherwise leakage can occur. If classes are imbalanced, report the base rate and consider class weighting or carefully designed sampling within training data only. Keep a final holdout untouched until model choices are settled.

A random forest classifier combines many decision trees and can capture non-linear patterns without requiring a simple straight-line relationship. It is a practical baseline, not an automatic choice. Fit preprocessing and model settings on training data, then produce probabilities on held-out data. Compare with a simple baseline such as predicting the majority class; a complex method is useful only if it improves decisions.

Evaluate and convert scores into action

A confusion matrix counts correct and incorrect positive and negative predictions at a chosen threshold. It reveals the practical trade-off: false positives consume outreach or investment; false negatives miss potential value. Choose the threshold in light of those costs and available capacity, rather than defaulting blindly to one half. Examine precision and recall alongside the matrix, and report the threshold used.

Two evaluation views

Confusion matrix

  • Counts outcomes at one threshold
  • Shows missed and unnecessary actions
  • Useful for capacity planning

ROC curve

  • Plots hit rate against false-alarm rate
  • Compares thresholds across scores
  • Does not choose business economics

A receiver operating characteristic (ROC) curve plots true-positive rate against false-positive rate as the threshold varies. A curve nearer the upper-left generally indicates stronger ranking than one near the diagonal, but ROC alone does not establish that probabilities are calibrated or actions profitable. For rare outcomes, precision-recall views may be more revealing. Check calibration by comparing predicted likelihoods with observed frequencies in groups, and validate performance across time and relevant customer segments.

Turn scores into an experiment. Rank eligible customers, define an action for score bands, and reserve a comparison group where practical. A high score might trigger a tailored success review; a low score may receive efficient standard support rather than no service. Record contacts, costs and outcomes, then assess incremental lift against the comparison group. Review fairness, privacy, consent and operational limits. Predictions describe patterns in past data; they should not be used to deny essential service or replace human review.

Responsible prediction loop
  1. 01

    Define

    Set outcome, horizon and decision

  2. 02

    Build

    Create point-in-time features

  3. 03

    Validate

    Test future-like data and costs

  4. 04

    Act

    Run a measured intervention

  5. 05

    Review

    Monitor drift and refresh carefully

See the code

Two worked analyses in Python are published on GitHub. Each comes with a sample dataset, so you can run the notebook and adapt the code to your own data.

Cohort-analysis — A cohort is a group of people who share a common characteristic over a certain period of time, such as the same sign-up month. The notebook groups customers into these cohorts and follows how each group performs over time.

RFM_analysis — RFM (Recency, Frequency, Monetary) analysis is a proven marketing model for behaviour-based customer segmentation. It groups customers by transaction history: how recently, how often and how much they bought. The notebook scores every customer on those three dimensions and divides them into segments, so you can pick out the customers most likely to respond to a promotion and shape personalisation from there.

Checklist

  • Confirm customer identifiers, dates, currencies and order rules.
  • Define first purchase and cohort period consistently.
  • Distinguish unobserved future cells from zero activity.
  • Compare retention at equal cohort ages.
  • Label period revenue, cumulative revenue and denominators.
  • Check cohort sizes, seasonality and large-order effects.
  • Set a future outcome and prevent information leakage.
  • Split by time and keep customer histories together.
  • Evaluate thresholds using error costs, ROC and calibration.
  • Pilot score-led actions and measure incremental results.

Continue reading

The newsletter

Sports Marketing Mavericks

An independent newsletter exploring fan engagement, technology and commercial growth in the sports industry.