JSPM

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

K-means in Javascript

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

kmeans

NPM version build status Test coverage David deps npm download

K-means clustering in JavaScript

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 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
}
*/

Test

npm install
npm test

Authors

License

MIT