Realtime and predictive cohorts

Add people to a cohort the moment their event arrives (realtime), or keep the people most likely to convert or spend in a cohort (predictive), with the options and API routes.

Embed
Preview of the card
<a href="https://lucidace.com/help/realtime-predictive-cohorts"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/83deb7d7-ae56-49b1-8c69-892816a6b3fd/social-card.svg?v=3e7ae33eec8b" alt="Realtime and predictive cohorts" width="600" height="315"></a>

Both build on ordinary cohorts. See Cohorts and actions over the API for the criteria tree.

Realtime cohorts

A dynamic cohort recalculates every 15 minutes. With realtime: true, the worker also adds a person as soon as one ingested event proves they qualify, without waiting for the next recalculation.

curl -X POST https://<app host>/v1/projects/$PROJECT/cohorts \
  -H "Authorization: Bearer $LUCIDA_KEY" -H "Content-Type: application/json" \
  -d '{"name":"Started checkout","kind":"dynamic","realtime":true,
       "filters":{"type":"and","values":[{"type":"performed","event":"checkout_started","window":{"days":7}}]}}'

You can also turn it on or off later with PATCH /v1/projects/{project_id}/cohorts/{id} and {"realtime": true}.

A definition is realtime-eligible only when it is an and/or tree made of:

  • performed with an event name, optional property filters, "at least once" (no count, or gte 1 / gt 0) and a window in days; and

  • person_property filters that all use eq.

An and needs every child satisfied by the same event; an or needs one. Anything else (counts above one, sequences, not_performed, in_cohort, lifecycle, other operators, saved actions, fixed date windows) is rejected with 400 when you turn realtime on.

Realtime only adds. People who age out of the window or whose property changes are removed by the 15-minute job, which stays the source of truth. If a realtime add fails it is logged and the job still catches the person.

Predictive cohorts

A predictive cohort trains a small explainable model (L2-regularised logistic regression on ln(1 + count) of recent events) that predicts whether a person does a goal event within a horizon, and keeps the highest-scoring people in a static cohort.

Field

Meaning

name, goal

The cohort name and the event to predict

features

1 to 20 event names whose recent counts are the inputs

property_features

[{event, key, value}]: count event only where key equals value (at most 20 features in total with features)

lookback_days

History behind each count, 1 to 180, default 30

horizon_days

Predict the goal within this many days, 1 to 90, default 7

selection

{"top_k": n} (1 to 10000) or {"threshold": p} (0 to 1, exclusive)

model_kind

linear (default) or interactions (also learns from each pair of features)

retrain_every_hours

1 to 8760; leave out to retrain only on request

retrain_from

Count the schedule from the last attempt (default) or success

seed

Seeds the training sample and the holdout split, default 0

target

conversion (default) or revenue

value_property

For revenue: the numeric goal-event property that holds the amount. With revenue, a threshold is an amount, not a probability

Training needs at least 50 people, with at least 5 who reached the goal and 5 who did not. With less, POST answers 422 and nothing is created. A quarter of the data is held out; the response carries the holdout auc, a calibration table, row counts, the base rate and the model weights per feature. A revenue model adds a mean absolute error and predicted-versus-actual revenue by decile. cohort_id is the static cohort that holds the selected people, usable anywhere a cohort is (insights, flags, destinations).

Routes (all under /v1/projects/{project_id}):

Route

What it does

GET /predictive-cohorts, POST /predictive-cohorts

List, create (and train)

GET /predictive-cohorts/{id}

Read, with metrics, model, scored_count, trained_at, last_error

PUT /predictive-cohorts/{id}

Change name, selection, retrain_every_hours, model_kind, retrain_from

POST /predictive-cohorts/{id}/retrain

Train and score now

DELETE /predictive-cohorts/{id}

Remove

In the app, the same form is under Predictive cohorts.

Updated