Skip to main content
Back

Athens Researchers' K-Sil Makes k-means 1200x Smarter Against Outliers

A silhouette-driven variant of k-means reweights points each iteration to reduce the pull of boundary and noisy samples, improving clustering across 15 datasets.

Pro

  • K-Sil weights points by a centroid-margin silhouette proxy inside every k-means iteration.
  • Centroid updates become a softmax-weighted mean, giving high-confidence points more pull.
  • An adaptive temperature is tuned by macro-averaged silhouette, avoiding manual hyperparameter search.
  • Improves silhouette, ACC, NMI, and ARI across 15 tabular, biomedical, text, and image datasets.
  • Per-iteration cost stays O(nkd), matching standard k-means with only constant-factor overhead.
  • Code is available at github.com/semoglou/ksil_clustering.

Clustering with k-means is the workhorse most people reach for when they need to group points quickly, but anyone who has run it on messy real data knows the drill: outliers drag centroids, ambiguous boundary points blur the partitions, and a few bad early assignments cascade into a mediocre final solution. A team from Athens University of Economics and Business, Athena Research Center, and the University of Ioannina has proposed a fix called K-Sil, a silhouette-driven, instance-weighted variant of k-means that quietly downweights the points most likely to be leading the centroid astray.

The idea is simple enough to slot into any k-means pipeline, but the paper backs it with a local convergence proof and experiments on 15 datasets spanning tabular, biomedical, text, and image data. Code is available on GitHub.

Where vanilla k-means breaks

Standard k-means updates each centroid as an unweighted mean of its assigned points. Under uncertain boundary assignments, noise and outliers, or heterogeneous within-cluster structure, that arithmetic mean can be pulled toward ambiguous regions, propagating early mistakes and yielding suboptimal partitions. Prior fixes typically weight instances using density scores or local outlier factors, which add complexity and modeling assumptions.

The authors' observation is that k-means already produces a natural signal of assignment confidence at every iteration: the distance from a point to its own centroid versus its distance to the next-nearest centroid. That gap is essentially a cheap approximation of the classic silhouette score, and it can be turned directly into weights.

Silhouette as within-cluster attention

For each point, K-Sil computes a centroid-margin silhouette proxy s_i in [0, 1]: values near 1 mean the point sits deep inside its cluster, values near 0 mean it is close to a decision boundary. Points with higher silhouette receive exponentially higher weights, while ambiguous or poorly fitted points are down-weighted. The centroid update then becomes a softmax-weighted mean of the cluster's points, which the authors describe as a within-cluster attention mechanism.

A temperature parameter tau controls how sharp that attention is. Small tau recovers standard k-means; large tau makes the update dominated by only the most confident points.

Effect of temperature on instance weights at tau=0.2 versus tau=2

An adaptive thermostat for the weighting

Manually tuning tau across datasets would defeat the purpose, so K-Sil adjusts it automatically using a macro-averaged silhouette score, which averages the mean silhouette of each cluster rather than of each point. Unlike the standard global mean silhouette used by sklearn, which is dominated by large clusters, the macro-averaged score gives each cluster equal weight, so it is sensitive to poorly separated or small clusters.

The update rule is an exponentiated-gradient step: if the macro silhouette improves between iterations, tau rises and the weights sharpen; if it drops, tau falls and the update becomes more exploratory. Tau is clipped between a minimum value and an upper bound that scales logarithmically with the largest cluster size to keep weight ratios from exploding.

The full loop per iteration looks like this:

  1. Compute per-point silhouette proxy from centroid distances
  2. Update tau based on change in the macro silhouette
  3. Compute weights w_i = exp(tau * s_i)
  4. Update each centroid as a softmax-weighted mean of its points
  5. Reassign labels by nearest centroid

Per-iteration cost is O(nkd), matching the standard k-means iteration order, with only constant-factor overhead.

What the numbers say

Across 15 datasets, K-Sil was compared against standard k-means, LOF-based and iterative LOF-based k-means, and OWk-means (which also uses silhouette-based penalties). On the HTRU2 pulsar dataset the silhouette score jumps from 0.684 to 0.749 and NMI from 0.442 to 0.572. On Wine, accuracy climbs from 0.931 to 0.972, and on Breast Cancer, ARI moves from 0.662 to 0.700. Gains are more modest but still positive on harder settings like Leukemia (d much greater than n) and large-k benchmarks such as Banking77 (k=77) and CLINC150 (k=151).

Even when initialized with k-means++, which already produces strong solutions, K-Sil is favorable on nearly all datasets and improvements occur more often and are typically larger in magnitude than the rare, very small regressions.

The centroid-margin proxy is also much cheaper than the exact silhouette. On HTRU2 it runs roughly 1200x faster than sklearn.metrics.silhouette_samples while maintaining a Pearson correlation of 0.89 with the exact values.

Where it helps and where it does not

K-Sil is a good fit when you already use k-means and want more robust centroids without switching algorithms. It leans on a geometric assumption: that internal separation aligns with the label structure you care about.

  • Best case: Well-separated clusters with some noise, boundary ambiguity, or heterogeneous density
  • Weak case: Datasets where silhouette geometry and label structure disagree. On Vehicle and Mice Protein, the authors had to use a UMAP embedding to make silhouette-based confidence align with class labels
  • Watch out: Under heavy outlier replacement, silhouette can inflate even as ARI drops, so internal metrics alone can mislead

The broader takeaway is that a k-means iteration already contains a usable confidence signal, and pushing that signal through a softmax turns each update into a form of attention over the cluster's own points, without extra models, extra passes, or fragile hyperparameters.