> 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 Churn Prediction

Use Kumo Engine to predict three kinds of customer churn: complete inactivity, stopped purchases, and abandonment of a specific high-value behavior such as streaming.
These predictions help retention teams reach engaged users before they stop returning, while there is still time to retain them.

Each prediction looks ahead from a user into the coming weeks.
Kumo Engine learns from the user's profile and the activity and purchase history connected to that user in the graph.

## Data and relationships

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

![Customer churn schema with users, events, and orders. The user\_id foreign keys in events and orders link to users.user\_id. Events use event\_timestamp as their time column, and orders use order\_date. The users profile fields signup\_date and plan are optional, and users has no time column.](/sdgm/_fern-files/nvidia-sdgm.docs.buildwithfern.com/abab6850bad30f7508f625f41b172b278ad9e4b57ba4925a02558f6a849f2ec5/_dot_dot_/images/diagrams/workflow-customer-churn-prediction-schema.svg)

| Table    | Required columns                                                                             | Purpose                                                                                                                              |
| -------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `users`  | `user_id` as the primary key, plus optional profile columns such as `signup_date` and `plan` | The customers, which every query scores.                                                                                             |
| `events` | `event_id` as the primary key, plus `user_id`, `event_timestamp`, and `event_type`           | The activity log, with one action per row and `event_type` naming the action, for example `login`, `stream`, `click`, or `purchase`. |
| `orders` | `order_id` as the primary key, plus `user_id`, `order_date`, and `order_value`               | The purchase log, used by the purchase-churn query.                                                                                  |

The time columns ensure that training and scoring use only the activity and purchase history recorded before the time each prediction looks ahead from.

The `users` table is a static entity.
Each forward-looking window is measured from the scoring time, the moment you run the prediction, rather than from a value on the user row.

Every query predicts a future window and restricts the users it scores.
The target counts a user's actions in the days after the scoring time and compares that count to `0` to define churn as no actions.

The trailing `WHERE` restricts predictions to recently active users, excluding users who have already churned.
The forward window is half-open: it excludes actions at the exact scoring time and includes actions through the end of the window.

## Predict which active users are about to go inactive

This query identifies currently engaged users who are about to become completely inactive.
`COUNT(events.*, 0, 30, days)` counts every action a user takes over the 30 days after the scoring time, and `= 0` defines churn as no activity.

The trailing `WHERE COUNT(events.*, -30, 0, days) > 0` restricts predictions to users active in the previous 30 days.
This lets the model distinguish recently active users who stay from those who leave, excluding users who have already left.

```python
from kumo.engine import PredictiveQuery

query_text = (
    "PREDICT COUNT(events.*, 0, 30, days) = 0 "
    "FOR EACH users.user_id "
    "WHERE COUNT(events.*, -30, 0, days) > 0"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Predict which recent buyers are about to stop buying

A user can keep logging in while they stop spending.
This query predicts whether each user will place no orders in the next 30 days.
`COUNT(orders.*, 0, 30, days) = 0` defines purchase churn as no purchases in the window.

`WHERE COUNT(orders.*, -90, 0, days) > 0` restricts predictions to users who bought at least once in the previous 90 days, excluding users who never purchased.
The purchase history window in the `WHERE` is wider than in the activity query because buying happens less often than logging in.

```python
query_text = (
    "PREDICT COUNT(orders.*, 0, 30, days) = 0 "
    "FOR EACH users.user_id "
    "WHERE COUNT(orders.*, -90, 0, days) > 0"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Predict which users are about to abandon one behavior

Users rarely churn all at once; they often first abandon a behavior central to the product's value, such as streaming on a media service or ordering on a marketplace.
This query filters the activity log to a single behavior and predicts whether the user will stop it.

`COUNT(events.* WHERE events.event_type = 'stream', 0, 30, days)` counts only streaming events in the forward window, and `= 0` flags users predicted to stop streaming even if they continue other activities.
The trailing `WHERE` still restricts predictions to recently active users.

Replace `'stream'` with the `event_type` for your product's core behavior.

```python
query_text = (
    "PREDICT COUNT(events.* WHERE events.event_type = 'stream', 0, 30, days) = 0 "
    "FOR EACH users.user_id "
    "WHERE COUNT(events.*, -30, 0, days) > 0"
)
query = PredictiveQuery(graph, query_text)
query.validate()
print(query.get_task_type())  # binary_classification
```

## Reading the predictions

Each query returns a probability that the specified kind of churn will occur for a user in the coming weeks.

Use the inactivity query to rank users most likely to become completely inactive and prioritize them for a re-engagement campaign.

Use the purchase query to identify users whose spending is about to stop even while they still log in, and target them with an offer or loyalty incentive.

Use the behavior query to identify users about to abandon your product's core behavior, often the earliest warning sign and the least costly time to intervene.

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

The 30-day forward window and the recent-activity windows in the `WHERE` clause are starting points.
Adjust the number of days to match how far ahead your team can act and how often your users normally return.
Refresh predictions as new activity and orders arrive so each decision reflects the latest behavior.