# node-kmeans

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

Latest version **1.1.9** (published 2019-06-26) · BSD license · 0 weekly downloads

## Install

```sh
npm install node-kmeans
pnpm add node-kmeans
yarn add node-kmeans
bun add node-kmeans
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.9 |
| Published | 2019-06-26 |
| First published | 2012-10-24 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | separate (@types/node-kmeans) |
| Module format | CommonJS |
| Node | >= v0.6.0 |
| Dependencies | 1 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 101 |
| Author | Philmod |
| Maintainers | philmod |
| Keywords | k-means, clustering |

## Links

- npm: https://www.npmjs.com/package/node-kmeans
- Repository: https://github.com/Philmod/node-kmeans
- Homepage: http://github.com/philmod/node-kmeans
- Issues: https://github.com/Philmod/node-kmeans/issues
- npm.io page: https://npm.io/package/node-kmeans

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) ^1.9.1

## Recent versions

- 1.1.9 (latest) — 2019-06-26
- 1.1.8 — 2018-01-28
- 1.1.7 — 2018-01-27
- 1.1.6 — 2018-01-27
- 1.1.0 — 2016-05-18
- 1.0.0 — 2016-04-03
- 0.0.1 — 2012-10-24

## README

# node-kmeans

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

![k-means](http://www.aishack.in/static/img/tut/kmeans-example.jpg)

## Installation

      $ npm install node-kmeans

## Example

```js
// 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 &lt;philippe.modard@gmail.com&gt;

---
_Source: https://npm.io/package/node-kmeans · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
