demo D374
Row Clustering: JavaScript Data Grid Demo
A cluster column over the numeric columns you tick: group the segments, colour them on a scatter, and watch the centres and sizes re-form as you filter
shadow: { kind: 'cluster' } · statistics.clusters() · statistics.autoK()
A cluster column groups the customers into segments by the numeric columns you tick. The scatter draws one colour per segment, the grid can group on the segment, and the table of centres and sizes is read from the grid. Filter to a region and the segments are found again over the rows that are left.
Segments as a column
Most segmentation happens somewhere else: an export, a notebook, a column pasted back in. Here the segment is a column of the grid. A cluster shadow column assigns every visible row a segment number, by k-means over the numeric columns you name, and it behaves like any other column. It sorts, filters, groups and exports, and a chart can take it as its series.
Tick two, three or four of the columns and the segments are found again over exactly those. Choose two, three or four segments, or press the button that lets the grid choose the number for you, which it does by comparing how well separated each choice is. Group by segment to see each one as a band of rows, or read the scatter, where every segment is its own colour.
What follows the filters
The clustering runs over the filtered rows. Pick a region and the grid segments only the customers left, so the colours, the sizes and the centres all describe what is on screen rather than the whole table. The centres are given in the columns’ own units, so a centre of 32 orders and 9 thousand spend reads as a customer, not as a standardised score. Columns are standardised before clustering by default, so a wide-range column does not decide the segments on its own.
How do I cluster rows in a data grid?
Add a column with a cluster shadow: shadow: { kind: 'cluster', columns: ['orders', 'spend'], method: 'kmeans', k: 3 }. Every visible row gets a segment id, which you can group, filter or use as a chart series. Read the centres and sizes with grid.statistics.clusters('segment'), and ask grid.statistics.autoK({ columns, criterion: 'silhouette' }) for the number of segments when you do not know it. Use method: 'dbscan' with eps for density-based segments instead.