> This page is for Kumo Engine.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/sdgm/llms.txt.

# Customer Lifetime Value Prediction

Customer lifetime value predicts future customer spending to guide investment, acquisition budgets, and retention efforts for accounts likely to grow.
This example uses Kumo Engine to estimate future revenue, identify customers likely to become high-value, and forecast repeat purchases for recently active customers.
Each prediction uses the customer's profile and the orders connected to that customer in the graph, which represents relationships between tables.

## Data and relationships

The example assumes a prepared Kumo Engine `graph`, a matching `snapshot`, and these tables:

![Customers and orders schema. Customers has primary key customer\_id and optional region and signup\_date fields. Orders has primary key order\_id, foreign key customer\_id linked to customers.customer\_id, time column order\_date, and amount. Customers are static, and forward windows start at scoring time.](/sdgm/_fern-files/nvidia-sdgm.docs.buildwithfern.com/5dff019ee88c78316fc0b06dea7223ca82522d9b733e1cdc6efc5ed82f4809a9/_dot_dot_/images/diagrams/workflow-customer-lifetime-value-prediction-schema.svg)

| Table       | Required columns                                                                                   | Purpose                                                                                                             |
| ----------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `customers` | `customer_id` as the primary key, plus optional profile columns such as `region` and `signup_date` | The customers, and the entity every query scores.                                                                   |
| `orders`    | `order_id` as the primary key, plus `customer_id`, `order_date`, and `amount`                      | The purchase log, with one completed order per row tied to a customer and `amount` holding the order's total value. |

The time column places every order in time so that training and scoring use only orders recorded before the prediction's reference time.

The `customers` table is a static entity: each forward-looking window is measured from the scoring time, when you run the prediction, rather than from a value on the customer row.

Lifetime value is a property of the customer, so every query aggregates the related `orders` child table.
A query that names a raw order column such as `orders.amount` for each customer is rejected because a customer has many orders, and Kumo Engine requires an aggregation to reduce them to one value.

Every query here predicts a future window.
The forward window is half-open: it excludes orders at the exact scoring time and includes orders through the end of the window.
Both day bounds must be zero or positive; a window that reaches into the past is rejected for a prediction target.

## Predict the revenue a customer will bring

This query estimates lifetime value as the money a customer will spend over the coming months.
`SUM(orders.amount, 0, 180, days)` sums the value of every order a customer places over the 180 days after the scoring time.

The target is future revenue rather than a category or flag.
A customer with no orders in the window contributes `0`.

```python
from kumo.engine import PredictiveQuery

query_text = (
    "PREDICT SUM(orders.amount, 0, 180, days) "
    "FOR EACH customers.customer_id"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # regression
```

## Flag the customers about to become high-value

To identify customers likely to qualify for a loyalty tier, a dedicated representative, or a retention offer, compare future spending to a cutoff.
This turns revenue estimation into a binary classification task.

`SUM(orders.amount, 0, 180, days) > 500` labels a customer high-value when their spending over the next 180 days exceeds 500.
The model learns to distinguish customers who will cross that threshold from those who will not.
Set the cutoff to your business's definition of high-value.

```python
query_text = (
    "PREDICT SUM(orders.amount, 0, 180, days) > 500 "
    "FOR EACH customers.customer_id"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Forecast how often an active customer will buy again

Subscription and replenishment businesses can use purchase frequency alongside revenue to assess lifetime value.
`COUNT(orders.*, 0, 180, days)` counts the orders a customer will place over the next 180 days, so the model predicts purchase frequency.
The trailing `WHERE COUNT(orders.*, -30, 0, days) > 0` limits scoring to customers who ordered in the previous 30 days, focusing the repeat-purchase forecast on recently active customers rather than dormant ones.

```python
query_text = (
    "PREDICT COUNT(orders.*, 0, 180, days) "
    "FOR EACH customers.customer_id "
    "WHERE COUNT(orders.*, -30, 0, days) > 0"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # regression
```

## Reading the predictions

The three queries support different decisions:

* The first returns expected revenue for each customer to rank customers by future value, set acquisition budgets, and allocate retention spending.
* The second returns the probability that a customer will exceed the high-value cutoff, supporting threshold decisions such as loyalty tier promotion or account manager assignment.
* The third returns the expected number of orders for recently active customers, helping replenishment or subscription teams identify customers likely to keep buying and those whose purchasing is slowing.

All three are estimates from past behavior, not guarantees.
Each is anchored at the time you run it, so the model uses only orders recorded before that moment and never sees the spending it predicts.

The 180-day forward window, the 500 high-value cutoff, and the 30-day recent-activity window are starting points.
Adjust the forward window to your planning horizon, the cutoff to your definition of high-value, and the recent-activity window to your purchase cycle.
Refresh scores as new orders arrive so each ranking reflects the latest spending.