包详细信息

ml-kmeans

mljs315.2kMIT6.0.0

K-Means clustering

cluster, kmeans, data, mining

自述文件

ml-kmeans

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

Zakodium logo

Maintained by Zakodium

NPM version Test coverage npm download

Installation

npm i 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

Sources

D. Arthur, S. Vassilvitskii, k-means++: The Advantages of Careful Seeding, in: Proc. of the 18th Annual ACM-SIAM Symposium on Discrete Algorithms, 2007, pp. 1027–1035. Link to article

License

MIT

更新日志

Changelog

5.0.0 (2019-06-29)

chore

  • update dependencies and remove support for Node.js 6 (5efe565)

BREAKING CHANGES

  • Node.js 6 is no longer supported.

6.0.0 (2023-02-24)

⚠ BREAKING CHANGES

  • remove withIterations options and instead export generatorKmeans

Miscellaneous Chores

4.2.1 (2018-08-15)

4.2.0 (2018-08-15)

4.1.0 (2018-08-11)

4.0.1 (2018-05-24)

Bug Fixes

  • keep initial value for empty centroids (94b0de9)

4.0.0 (2018-05-23)

Features

  • implement kmeans++ initialization algorithm (007f3b1)

BREAKING CHANGES

  • kmeans++ is now the default initialization algorithm instead of mostDistant

3.1.0 (2018-05-16)

3.0.1 (2018-05-04)

3.0.0 (2016-10-07)

Bug Fixes

  • remove unneeded array creations in updateClusterID (b2957d5)

Features

  • accepts distance function as parameter (68993a1)
  • allows to compute a new array of points their cluster id (254f9a9)
  • return a generator in the withIterations option (3b4c7c6)
  • return the number of iteration done (75fd42e)
  • returns the error and the size of each cluster (e85aab7)
  • when maxIterations is 0, iterates until converge (220c828)

2.0.0 (2016-09-27)

Features

  • initialize the points as parameter (fbe993d)
  • initialization: moreDistant initialization (d098f43)
  • initialization: random initialization (9e58baf)

BREAKING CHANGES

  • instead of asking for a manual initialization, ask for k and the initialization method

1.0.0 (2016-09-15)

Chores

BREAKING CHANGES

  • rename option variables to more understandable names

0.1.0 (2015-07-22)