JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 66548
  • Score
    100M100P100Q166708F
  • License MIT

K-Means clustering

Package Exports

  • ml-kmeans

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ml-kmeans) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ml-kmeans

NPM version build status Test coverage npm download

K-means clustering aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean.

Installation

npm install --save ml-kmeans

API Documentation

Example

const kmeans = require('ml-kmeans');

let data = [[1, 1, 1], [1, 2, 1], [-1, -1, -1], [-1, -1, -1.5]];
let centers = [[1, 2, 1], [-1, -1, -1]];

let ans = kmeans(data, 2, { initialization: centers });
console.log(ans);
/*
KMeansResult {
  clusters: [ 0, 0, 1, 1 ],
  centroids: 
   [ { centroid: [ 1, 1.5, 1 ], error: 0.25, size: 2 },
     { centroid: [ -1, -1, -1.25 ], error: 0.0625, size: 2 } ],
  converged: true,
  iterations: 1
}
*/

Authors

License

MIT