Skip to content

clusters

function clusters(ldIn, labels): Clusters;

Defined in: metrics/separability.ts:54

Group points by label and compute the centroids the label-based measures need.

Build this once and pass it to each of them; it is the shared setup, not a measure itself.

ParameterType
ldInPointsInput
labelsreadonly unknown[]

Clusters

import { clusters, silhouette, daviesBouldin } from "@saehrimnir/sickle";
// `projection` is number[][], 200 x 2; one label per point, 4 classes.
const cl = clusters(projection, labels); // build once, pass to every measure
cl.keys.length; // 4
cl.sizes; // Uint32Array [50, 50, 50, 50]
silhouette(projection, cl).value; // 0.8838
daviesBouldin(projection, cl).value; // 0.1603