Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master


latest commit 184c5e106a
Tom MacWright authored December 11, 2012
Octocat-spinner-32 demo Finalish touches September 11, 2012
Octocat-spinner-32 examples Churn. testing September 09, 2012
Octocat-spinner-32 test More tests September 13, 2012
Octocat-spinner-32 .DS_Store Progress August 24, 2012
Octocat-spinner-32 LICENSE Create LICENSE December 11, 2012
Octocat-spinner-32 Improve readme October 11, 2012
Octocat-spinner-32 kmeans.js More tests September 13, 2012
Octocat-spinner-32 package.json Keep moving, update graphics August 14, 2012


k-means clustering in configurable dimensions, in-browser and with node.js.

In order to support learning about the algorithm, this library is split into very small bits, so you can use each step separately.

var kmeans = require('kmeans');

var d = [1, 2, 3];
// take a random sample of the array d
var s = kmeans.sample(d, 1);

// [1]

// Get the euclidean distance between two points represented as
// arrays
console.log(kmeans.dist([0, 0], [0, 1]), 1);
// 1

In order to support a variety of data, accessors are used in functions like means_clusters(x, means, distance, val) (though with good defaults - distance defaults to euclidean, val defaults to function(x) { return x; }).

var c = kmeans.means_clusters([3], [3, 4])
// 1


npm install --save kmeans


npm test

License is WTFPL

Something went wrong with that request. Please try again.