clustering-tfjs

GPU-accelerated clustering for JavaScript & TypeScript

K-Means, Spectral, Agglomerative, HDBSCAN and SOM — a scikit-learn-style API for Node.js and the browser.

npm install clustering-tfjs
★ Star on GitHub

K-Means, Spectral, Agglomerative, HDBSCAN and SOM — clustered live in your browser

Five toy datasets (rows) × five algorithms (columns). Click below to cluster every cell off the main thread on the accelerated backend, each coloured by its computed labels using a colorblind-safe palette. Noise points are gray.

Run this exact result in your own code

Click any cell in the grid above (or focus one and use the arrow keys, Enter to select) to see the real, runnable code — the same constructor calls and parameters this page just ran, on the backend it's using now.

Blobs · Spectral
npm install clustering-tfjs
★ Star on GitHub

Accelerated clustering, benchmarked live on your hardware

Sweep the RBF-affinity clustering workload across growing sample sizes on each backend in turn. Every measured median is plotted the instant it lands, so the O(n²) scaling law draws itself — and the accelerated line pulls away from CPU as n grows.

Ready — click to benchmark.
The data being clustered
— peak speedup
— throughput
How this is timed
  • Each backend runs float32 on byte-identical input tensors.
  • The dataset is uploaded to each backend once, outside the timed region — timing measures compute, not host→device transfer.
  • 3 warmup runs are discarded to absorb shader compile / wasm init / lazy kernel registration before any size is timed.
  • Each timed rep brackets the affinity construction plus its single awaited readback (await affinity.data()), so deferred GPU work is counted.
  • The plotted figure is the median of 7 timed reps (protocol floor: ≥ 5).
  • After every rep tf.memory().numTensors must return to baseline — a leak aborts that backend instead of plotting a drifting number.
  • A cross-backend checksum on the affinity matrix confirms both backends computed the same kernel.
Workload
Spectral RBF affinity · O(n²·d)
Samples (n)
250 → 8,000
Features (d)
32
Dtype
float32
Warmups · reps
3 · 7
CPU backend
—
Accelerated backend
—
tfjs version
—
View the library on GitHub →