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
4 hours ago (2.2.0)
function k_means_pp
k_means_pp(
points: I_points_data,
k: number,
range: Range,
): Result

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

This function implements the initialization step of K-means++, which selects initial centroids in a way that improves the final clustering result compared to standard K-means.

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.

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_pp } from "@ppz/k-means-pp";

---- OR ----

Import directly with a jsr specifier

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

Add Package

npx jsr add @ppz/k-means-pp

Import symbol

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

Add Package

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

Import symbol

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

Add Package

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

Import symbol

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

Add Package

bunx jsr add @ppz/k-means-pp

Import symbol

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