Wkmeans: Weighted k-means (minimises WWCSS)

View source: R/nugget-clustering.R

WkmeansR Documentation

Weighted k-means (minimises WWCSS)

Description

k-means in which each observation carries a non-negative weight. Cluster centres are weighted means and the objective is the Weighted Within-Cluster Sum of Squares \sum_c \sum_{i \in c} w_i \lVert x_i - \mu_c \rVert^2.

Usage

Wkmeans(x, k, weights = rep(1, nrow(x)), nstart = 10, max_iter = 100)

Arguments

x

Numeric matrix, observations in rows.

k

Number of clusters.

weights

Non-negative weight per observation (default all 1).

nstart

Number of random restarts (best WWCSS kept).

max_iter

Maximum Lloyd iterations per start.

Value

A list with cluster, centers and wwcss.

References

Dey, T., Duan, Y., Cabrera, J. & Cheng, X. (2025). WCluster: Clustering and PCA with Weights, and Data Nuggets Clustering.

See Also

nugget_cluster, Whclust

Examples

set.seed(1)
x <- rbind(matrix(rnorm(20 * 3, 0), 20), matrix(rnorm(20 * 3, 5), 20))
Wkmeans(x, k = 2, weights = runif(40, 1, 5))$cluster[1:5]

MosaiClusteR documentation built on Oct. 25, 2026, 1:08 a.m.