New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-kmeans

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-kmeans

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

  • 1.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
decreased by-15.36%
Maintainers
1
Weekly downloads
 
Created
Source

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
  • 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 <philippe.modard@gmail.com>

Keywords

FAQs

Package last updated on 26 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc