Skip to content

K-Means Clustering

I. Finding groups without labels — overview of K-Means Clustering

    %%{init: { 'theme': 'base', 'themeVariables': { 'edgeLabelBackground': '#fff' }}}%%
flowchart LR
    A1["Unlabeled data"] -- "Assign to nearest centroid, then move the centroid" --> B1["K stable groups"]
    style A1 fill:#f9f9f9,stroke:#333,stroke-width:1px
    style B1 fill:#e1f5fe,stroke:#01579b,stroke-width:1px
  

Definition: an unsupervised learning algorithm that partitions data into K groups without any labels, by repeatedly assigning each point to the nearest centroid and recomputing each centroid as the mean of the points assigned to it, until the assignments stop changing

Characteristics: ( No Ground Truth ) there is no correct answer to learn from — the algorithm discovers structure rather than reproducing a known label, which makes evaluation a judgment call rather than a score ( Iterative Convergence ) alternating assignment and update is guaranteed to converge, but only to a local optimum that depends on the initial centroids ( Distinct from K-NN ) the shared “K” causes constant confusion: K-NN is supervised and classifies one new point using labeled neighbors, while K-Means is unsupervised and partitions an entire unlabeled dataset

II. Detailed mechanisms and components of K-Means

A. The clustering mechanism of K-Means

    graph TD
    A2["Choose K initial centroids"] -- "Assignment step" --> B2["Assign each point to its nearest centroid"]
    B2 -- "Update step" --> C2["Move each centroid to the mean of its members"]
    C2 -- "Assignments changed" --> B2
    C2 -- "Assignments stable" --> D2["Final clusters"]
  

B. Core components and detailed functions

ComponentDetailed DescriptionNotes
CentroidThe mean position of a cluster’s members, serving as that cluster’s representative pointCluster Center
K-ValueThe number of clusters, which must be fixed in advance by the practitioner rather than learnedHyperparameter
InertiaThe total squared distance from each point to its centroid — the quantity the algorithm minimizesWithin-Cluster SSE
InitializationThe choice of starting centroids, which decides which local optimum is reachedK-Means++

III. Technical challenges and trends of K-Means

A. Limitations and optimization strategies

ItemDetailed ContentSolution
Choosing KThe number of clusters is an input, not an output, and a wrong K produces confident but meaningless groupsElbow Method, Silhouette Score
Cluster Shape AssumptionOnly roughly spherical, similarly sized clusters are recovered; elongated or nested shapes are split incorrectlyDBSCAN, Gaussian Mixture Model
Initialization SensitivityPoor starting centroids converge to a bad partitionK-Means++, multiple restarts
OutliersBecause centroids are means, a few extreme points pull a cluster center away from its membersK-Medoids, outlier removal

B. Technology trends

( Customer Segmentation ) it remains the standard first pass for segmentation, anomaly grouping, and image color quantization, because it is fast, explainable, and needs nothing labeled. ( Embedding Clustering ) applied to embedding vectors rather than raw features, it groups semantically similar documents or users, and is used to organize retrieval corpora and deduplicate large text collections.