Skip to content
p.mba

Type to search tools, guides, glossary terms, frameworks, formula sheets and pages.

Menu

Glossary · Data Science & AI

K-Means Clustering

Also called: k-means · Lloyd's algorithm

An unsupervised algorithm that groups observations into k clusters by repeatedly assigning each point to the nearest cluster center and recomputing the centers.

Definition

K-means clustering partitions data into a chosen number k of groups so that the total squared distance between points and their cluster's mean is as small as possible. The standard procedure, often attributed to Stuart Lloyd and named k-means by James MacQueen in 1967, alternates between assigning points to the nearest center and moving each center to the mean of its points until assignments stop changing. Variables should be standardized first so that ones with large units do not dominate, and the result depends on the starting centers and the choice of k. In marketing it is a common first step in needs-based or behavioral segmentation.

Formula

min⁡S1,…,Sk∑j=1k∑xi∈Sj∥xi−μj∥2\min_{S_1,\dots,S_k} \sum_{j=1}^{k} \sum_{x_i \in S_j} \lVert x_i - \mu_j \rVert^2
TeX source
\min_{S_1,\dots,S_k} \sum_{j=1}^{k} \sum_{x_i \in S_j} \lVert x_i - \mu_j \rVert^2

Worked example

Hypothetical: an online retailer clusters 50,000 customers on standardized order frequency, average basket size and discount usage. With k = 4 it finds frequent full-price buyers, occasional big-basket buyers, deal seekers and lapsed customers, each of which gets a different campaign.

Try it in a tool

  • Unsupervised Learning: Machine learning that finds structure, such as groups or underlying dimensions, in data that has no labeled outcome.
  • Market Segmentation: Dividing a market into groups of customers whose needs or responses to marketing differ enough to justify different offers.
  • Machine Learning: Methods that let computers learn patterns from data to make predictions or decisions without being explicitly programmed with rules.
  • Standard Deviation: A measure of how spread out values are around their mean, in the same units as the data.

Courses

More in Data Science & AI

All glossary terms