• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    JavaScript
  • Created about 12 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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);
});

Inputs

  • vectors is a nXm array (n [lines] : number of points, m [columns] : number of dimensions)
  • options object:
    • k : number of clusters
    • distance (optional) : custom distance function returning the distance between two points (a,b) => number, default Euclidian Distance
    • seed (optional) : value that can be provided to get repeatable cluster generation
  • callback node-style callback taking error and result argument

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 <[email protected]>

More Repositories

1

node-pid-controller

Node.js PID controller
JavaScript
125
star
2

google-cloud-build-slack

Slack integration for Google Cloud Container Builder, using Google Cloud Functions
JavaScript
78
star
3

gcb-docker-compose

Example on how to run integration tests on Google Container Builder, using docker-compose.
JavaScript
45
star
4

node-recommendations

Node.js recommendations module
JavaScript
10
star
5

node-redis-lock

Locks in Redis.
JavaScript
9
star
6

clarifai-go-webcam

Stream webcam images from the browser (webRTC) to a server that detects tags using Clarifai API
JavaScript
9
star
7

Labview-JSON

A library to encode Labview cluster into JSON format.
9
star
8

auto-deploy-gcf

Example to automatically deploy new code to GCF, using a GCB trigger
JavaScript
8
star
9

google-builder-webhook

Webhook integration for Google Cloud Container Builder, using Google Cloud Functions
JavaScript
2
star
10

node-example-websocket

Websocket server for socket.io chat example
JavaScript
2
star
11

wcbrazil

Simple page to see the last scores of the World/Euro Cup, realtime comments, and scores of the bets
JavaScript
2
star
12

node-example-kubernetes

Deploy node-example on Kubernetes
1
star
13

ServerData

This is a web server that listens to datas (/datas) in JSON format, and stores it as time-series in Apache Cassandra.
JavaScript
1
star
14

url-shortener

Webserver to shorten url and redirect to pages - using DynamoDB
JavaScript
1
star
15

cloud-builder-mailgun

Google Cloud Builder image to send emails with mailgun
JavaScript
1
star
16

google-cloud-build-gulp

Example on how to use gulp with Google Cloud Container Builder
JavaScript
1
star
17

test-gcb-trigger

Test Dockerfile cache with both GCB trigger types
Dockerfile
1
star
18

node-example-frontend

Frontend server that serves the HTML for socket.io chat example
JavaScript
1
star
19

data2server

The goal is to send the data acquired in Labview to a web server (RESTful)
1
star
20

gcb-example

Simple example for Google Cloud Container Builder
JavaScript
1
star