Skip to main content

A JS/TS implementation of the k-means and k-means++ clustering algorithm.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
5 hours ago (2.2.0)
function k_means
k_means(
points: I_points_data,
k: number,
range: Range,
means?: Points,
count?: number,
): Result

Performs the K-means clustering algorithm on a set of points.

Parameters

points: I_points_data
  • The input data points to be clustered.
  • The number of clusters to form.
range: Range
  • The range of possible values for each dimension of the points.
optional
means: Points
  • Optional initial cluster centroids. If not provided or insufficient, random centroids will be generated.
optional
count: number = 0
  • Optional counter for tracking the number of iterations. Default is 0.

Return Type

Result

A Result object containing the final clusters, their means, and the number of iterations.

Add Package

deno add @ppz/k-means-pp

Import symbol

import { k_means } from "@ppz/k-means-pp";

---- OR ----

Import directly with a jsr specifier

import { k_means } from "jsr:@ppz/k-means-pp";

Add Package

npx jsr add @ppz/k-means-pp

Import symbol

import { k_means } from "@ppz/k-means-pp";

Add Package

yarn dlx jsr add @ppz/k-means-pp

Import symbol

import { k_means } from "@ppz/k-means-pp";

Add Package

pnpm dlx jsr add @ppz/k-means-pp

Import symbol

import { k_means } from "@ppz/k-means-pp";

Add Package

bunx jsr add @ppz/k-means-pp

Import symbol

import { k_means } from "@ppz/k-means-pp";