Segment Overview

Interactive segment comparison heatmap for Jupyter notebooks.

Rows are metrics, columns are segment values. Click a cell to see that metric's distribution for the segment; shift-click a second cell in the same row to compare two distributions side by side. segment_col and metrics are also editable from the widget's sidebar without re-running the cell.

How it works

Diff mode compares two groups in depth. Segment Overview does the opposite: it compares every level of a segment at once, on several metrics, shallowly — so you know which pair is worth diffing before you spend a widget on it. Six acquisition channels across five metrics is one heatmap here and fifteen diffed graphs otherwise.

The computation is two steps. Each path gets a value for each of your path metricslength, duration, conversion via has_event, time to purchase via time_between. Then, for every level of segment_col, those per-path values are collapsed into one number by the metric's agg. Metrics become rows, segment levels become columns, and the colour is the metric's value read across the row.

Which is why agg is required here and nowhere else. A distribution has no single summary: mean follows the tail, median follows the bulk, and for skewed quantities like session duration the two can point in opposite directions. Adding the same metric twice under different aggregations is a normal thing to do — q95 next to median says whether a segment is slower overall or just has a heavier tail.

Two rows are always present without being asked for: segment_size and segment_share. Read them first. A level holding 0.4% of the paths will happily post the most extreme value in every row, and it means nothing.

complement_distance is the odd one out among the aggregations. Instead of summarizing a level's values, it measures the Wasserstein distance between that level's whole distribution and the pooled distribution of every other level — "how unlike the rest is this group?" as a single number. It catches differences the mean hides, such as one level splitting into fast and slow sub-populations whose average lands exactly on everyone else's.

Clicking a cell opens the underlying distribution rather than the number; shift-clicking a second cell in the same row overlays two of them, which is usually enough to tell a real shift from a couple of outliers.

Dynamic segments split paths, not just group them. Metrics are computed per (path, segment level) pair, so a user active both inside and outside an incident window contributes a fragment to each column — you are comparing behavior during the window against behavior outside it, not one set of users against another. For a static segment (channel, A/B arm, cluster label) each path belongs to exactly one level and this collapses back to the obvious reading. See Static and dynamic segments.

Usage

stream.segment_overview(
    segment_col="plan",
    metrics=[
        {"metric": "length", "agg": "mean"},
        {"metric": "event_count", "metric_args": {"event": "purchase"}, "agg": "mean"},
    ],
)

Examples

Basic

stream.segment_overview(
  segment_col="platform",
  metrics=[
      {"metric": "length", "agg": "mean"},
      {"metric": "event_count", "metric_args": {"event": "purchase"}, "agg": "mean"},
  ],
)

Parameters

Data

Data parameters change the computed result. They are exactly the arguments of the widget's headless twin stream.segment_overview_data() — see headless mode below.

ParameterTypeDescription
segment_colstr, optionalSegment column to split by; must be one of schema.segment_cols. Required (directly or via the sidebar) before the widget computes anything.
metricslist of dict, optionalMetric configurations, each with a "metric" key, optional "metric_args", and an "agg" key ("mean", "median", "q5", "q25", "q75", "q95", or "complement_distance") controlling how per-path values roll up across a segment. See the Path Metrics documentation page for the metric reference.
path_colstr, optionalPath ID column override; defaults to schema.path_col.

Display

Display parameters only affect how the widget is rendered.

ParameterTypeDescription
heightint, default 480Widget height in pixels.
sidebar_openbool, default TrueWhether the sidebar starts open.
state_filestr, optionalJSON file the widget state is bound to; see Saving widget state.

Headless mode

stream.segment_overview_data()

Compute aggregated metrics across segment values (headless).