Skip to content
Node.js asynchronous implementation of the clustering algorithm k-means.
JavaScript Makefile
Latest commit e6337ca May 18, 2016 @Philmod 1.1.0
Failed to load latest commit information.
lib eslint May 18, 2016
test eslint May 18, 2016
.eslintignore eslint May 18, 2016
.eslintrc eslint May 18, 2016
.gitignore first implementation Oct 22, 2012
Makefile More verbose tests May 18, 2016
README.md update readme too Apr 3, 2016
index.js eslint May 18, 2016
package.json 1.1.0 May 18, 2016

README.md

node-kmeans

Node.js asynchronous implementation of the clustering algorithm k-means

k-means

Installation

  $ npm install node-kmeans

Example

// Data source: LinkedIn
const data = [
  {'company': 'Microsoft' , 'size': 91259, 'revenue': 60420},
  {'company': 'IBM' , 'size': 400000, 'revenue': 98787},
  {'company': 'Skype' , 'size': 700, 'revenue': 716},
  {'company': 'SAP' , 'size': 48000, 'revenue': 11567},
  {'company': 'Yahoo!' , 'size': 14000 , 'revenue': 6426 },
  {'company': 'eBay' , 'size': 15000, 'revenue': 8700},
];

// Create the data 2D-array (vectors) describing the data
let vectors = new Array();
for (let i = 0 ; i < data.length ; i++) {
  vectors[i] = [ data[i]['size'] , data[i]['revenue']];
}

const kmeans = require('node-kmeans');
kmeans.clusterize(vectors, {k: 4}, (err,res) => {
  if (err) console.error(err);
  else console.log('%o',res);
});

Intputs

  • 'vectors' is a nXm array (n [lines] : number of points, m [columns] : number of dimensions)
  • options object:
    • k : number of clusters

Outputs

An array of objects (one for each cluster) with the following properties:

  • centroid : array of X elements (X = number of dimensions)
  • cluster : array of X elements containing the vectors of the input data
  • clusterInd : array of X integers which are the indexes of the input data

To do

  • Technique to avoid local optima (mutation, ...)

Author

Philmod <philippe.modard@gmail.com>

Something went wrong with that request. Please try again.