Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

name: op-group-kmeans
description: Segment records into k clusters by seeded, deterministic k-means over a vector of numeric members; keys cluster_1..cluster_k by descending size.
kind: operator
category: GROUP
operator: GROUP_KMEANS
type: reference
applies_to: process, compose, predict
examples_tags: [multivariate, buffered-pipeline]

Use when

Finds k segments of rows that are alike across several numbers at once, such as customer types by spend, visits and tenure.

Questions it answers:

  • What natural customer segments do spend, visits and tenure suggest?
  • Which respondent types stand out across the rating battery?

Use something else:

  • GROUP_CATEGORY when you already know the groups.
  • GROUP_QUANTILE when you want bands of one number.

Params

NameTypeDefaultDescription
kint(required)2 ≤ k ≤ distinct tuples.
seedint0int64; 0 = fixed.
max_iterint100Lloyd iterations per start.
n_initint10Seeded starts; lowest within-SS wins.
standardizebooltruez-score each member first.
missingenumlistwiselistwise only.
fitenumglobalglobal (once over the filtered set) or within (refit per bucket of the earlier groupers; no-op outermost): each refit is a components buckets entry, warns with details.group_key; k above a bucket’s distinct tuples fails it alone (PULSE_SLOT_FAILED).

weight: frequency only (a row is w points).

Slot: exactly one of vector (a vectors entry) / fields; no field. Key column GROUP_KMEANS_<vector> or _<first fields entry>.

Inputs

Members: see ## Contract.

Output

Keys cluster_1…cluster_k, emitted largest first (ties: lexicographic centroid). A null member → n_null.

Components

  • The params, members, center / scale, distinct_points, buckets {key, count, size, within_ss, centroid, centroid_standardized}, total_ss, within_ss, between_ss, between_ss_ratio, iterations, converged, best_init.

Contract

  • Member types (vector, fields): f32, f64, packed_bool, u16, u32, u4, u64, u8 (packed_bool only under coerce: "binary"; a vec_* field’s elements are members); any other is PULSE_VECTOR_MEMBER_TYPE.
  • Weight: weighted under frequency weights only; a probability weight is PULSE_WEIGHT_UNSUPPORTED (k-means has no probability-weighted form: a sampling weight does not make a row several coincident points, and no reference implementation defines design-weighted clusters).
  • Streaming: buffered only; components none. k-means fits over every row before any label exists; the request runs buffered and serially under DecodeWorkers / ShardWorkers, and a crosstab falls back to the buffered arm.
  • Components: total_n, n_null, k, seed, n_init, max_iter, standardize, members, center, scale, distinct_points, buckets, total_ss, within_ss, between_ss, between_ss_ratio, iterations, converged, best_init.

Gotchas

  • Squared Euclidean only (the sq_euclidean registry metric); no metric param.
  • Labels depend only on the member tuples, never on row or shard order.
  • Buffered, never merged; predict row_buffer_bytes = n·p·8 + k·p·8.
  • Best start at max_iter: PULSE_MATRIX_NOT_CONVERGED (solver kmeans_lloyd).
  • include on groups: PROCESSING_CONFIG.

See