Skip to content

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

Notifications You must be signed in to change notification settings

Intervox/node-kmeans

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-kmeans

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

k-means

Installation

  $ npm install node-kmeans

Example

// Data source: LinkedIn
var 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
var vectors = new Array();
for (var i = 0 ; i < data.length ; i++)
  vectors[i] = [ data[i]['size'] , data[i]['revenue']];

var kmeans = require('node-kmeans');
kmeans.clusterize(vectors, {k: 4}, function(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
    • distance : [optional] distance function

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>

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%