Skip to main content

For AI agents: a Markdown version of this page is at https://docs.snowplow.io/docs/signals/datasets.md. The index of all documentation pages is at https://docs.snowplow.io/llms.txt, and the index for this section is at https://docs.snowplow.io/docs/signals/llms.txt.

Build ML training and evaluation datasets

Open in Colab

The Signals dataset builder creates datasets from your Snowplow event data, with one row per moment in time and the values your application would have seen at that moment. It computes those values from your existing attribute groups and agentic contexts, using only the events that occurred up to each moment. A model trained or tested on the dataset sees the same values it receives in production.

You can use the dataset builder for two kinds of work:

  • Train a machine learning model: build a labeled dataset of features, train a model on it, and serve the same attributes to the model in real time. See Build a training dataset for a machine learning model.
  • Evaluate a decision model: rebuild the moments your application would have called a model such as a System One model or an LLM prompt, the state it would have sent, and what each user did next. Then ask the model at every moment and check its answers before you change anything in production. See Evaluate decision models on past traffic.

Start by connecting to Signals to create a Signals client object.

Why point-in-time correctness matters​

When your application calls a model in real time, it only has access to events that have happened so far in the session. If a dataset includes values computed from the full session, including events after the moment of the call, the model trains or is tested on information it will never have in production. This is called data leakage. It makes a model look better in testing than it performs after deployment.

The dataset builder prevents leakage by construction. It computes each value using only events that occurred before the moment, from the same attribute group and agentic context definitions that power your real-time Signals deployment.

How it works​

A dataset build has three stages:

Diagram: three stages of a dataset build. Anchors: session or event anchors, or your own table of moments, give one row per moment. Context: attributes from earlier events and agentic contexts at each moment give values as they stood. Assembly: anchors with their context, plus labels or outcome columns, give one dataset table.

  1. Anchors: decide the moments that become rows. Signals can derive them from your events, by session goal or by matching events, or you can supply your own table. See Choose dataset anchors.
  2. Context: for each anchor, compute attribute values and agentic context entries using only the events before it. See Add context and outcomes.
  3. Assembly: join anchors with their context, plus labels or outcome columns, into a single table with one row per anchor.

For example, with two attributes (product_view_count and add_to_cart_count) and a transaction goal, the final dataset looks like this:

domain_sessionidanchor_tslabelproduct_view_countadd_to_cart_count
abc-1232024-01-15 09:32:00152
def-4562024-01-15 10:01:00030
ghi-7892024-01-16 14:22:00184

Each row captures the values as they were at the anchor timestamp, not at the end of the session.

Supported warehouses​

The dataset builder supports Snowflake only. A Signals warehouse connection is required for managed runs. If you build the SQL yourself, you can run it directly against your warehouse without a connection configured in Signals.

FeatureSnowflake
Session anchors✅
Event anchors✅
User-supplied anchors✅
Outcome columns✅
Agentic contexts✅
Managed runs✅
Self-built SQL✅

The dataset builder computes attributes from stream attribute groups only. It doesn't support warehouse attribute groups yet. The attribute groups can use any attribute key, including custom keys read from an entity or an event property.

Workflow​

Building and using a dataset follows this process:

  1. Define your attribute groups, and your agentic contexts if your model reads recent activity
  2. Choose the anchors that define the rows
  3. Add context and outcomes to each row
  4. Run the build, either as a managed run or by executing the SQL yourself
  5. Train your model on the dataset, or evaluate a decision model against it
  6. Serve the same attributes and agentic contexts to your model in real time via Retrieve attributes and Retrieve agentic contexts

For a complete walkthrough, from defining attributes to training and serving a model, follow Train and serve a purchase propensity model.

Was this page helpful?