k-means-pp
v2.3.1
Published
A JS/TS implementation of the k-means algorithm.
Downloads
24
Readme
k-means-pp.js
A JS/TS implementation of the k-means and k-means++ clustering algorithm.
- Implements both k-means and k-means++ algorithms
- Supports multi-dimensional data points
- Works in any JavaScript environment, including browsers, Node.js, Deno and more
Installation
deno
deno add @ppz/k-means-pp
npm
npm install k-means-pp
Usage
// import { KMPP } from '@ppz/k-means-pp' // deno
import { KMPP } from 'k-means-pp' // nodejs
const kmpp = new KMPP({
dimension: 3,
data: [
[1,2,3],
[0, 270, 103],
[3,4,5],
[0,0,0],
[100, 200, 1],
[0, 310, 120],
[10, 320, 90],
[100, 201, 3],
[0, 300, 100],
[1000, 2000, 1],
],
})
const result1 = kmpp.cluster(8) // perform k-means++
console.log(result1.means)
const result2 = kmpp.cluster(6, 'k_means')
console.log(result2.means)