
Splitting data into groups around centres found iteratively.K-means clustering is an unsupervised learning algorithm that partitions a dataset into a predefined number of clusters, each represented by its centroid (the mean of its points). The goal is to minimize the within-cluster variance, making points in the same cluster as similar as possible while keeping different clusters distinct. It is one of the simplest and most widely used clustering methods, often serving as a baseline for more complex approaches.
The term 'k-means' was first used by James MacQueen in 1967, though the core idea dates back to Hugo Steinhaus in 1956 and Lloyd's algorithm (1957) for pulse-code modulation.
The algorithm starts by randomly initializing k centroids. It then iterates two steps: (1) assign each data point to the nearest centroid, and (2) recompute each centroid as the mean of all points assigned to it. These steps repeat until the centroids stop changing significantly. The result depends on the initial placement, so it is common to run the algorithm multiple times with different seeds and pick the best outcome. The number of clusters k must be chosen in advance, often using the elbow method or silhouette analysis.
K-means is used for customer segmentation in marketing, image compression by reducing color palettes, and anomaly detection by identifying points far from any centroid.
K-means is so efficient that it can cluster millions of points in seconds, but it assumes clusters are spherical and similar in size, which is rarely true in real data.












