# k-Means Clustering

> It splits data into k groups. It moves k centre points until they stop.

**Field:** Artificial Intelligence  
**Category:** Machine Learning  
**Also known as:** k-Means, K-Means Algorithm

## Think of it like

Think of it like three ice cream carts on a beach. You place them so no one walks too far.

## Definition

k-means clustering is a method that splits data into k groups, where k is a number you choose. It starts by dropping k centre points at random. Each example joins the group of its nearest centre. Then each centre moves to the middle of its group. These two steps repeat until the centres stop moving.

## Example

Emma runs k-means with k set to 4 on her customers' spending. It finds four groups, from rare small spenders to weekly big spenders.

## Why it matters

It is one of the simplest and fastest ways to find groups in data that has no labels.

## Common mistake

Picking k without thinking. The method always returns k groups, even if the data really has two or ten.

## Three principles

- **You pick k.** The number of groups.
- **Join the nearest.** Each point picks a centre.
- **Move and repeat.** Until the centres settle.

## Related terms

- [Clustering](https://learn.benibix.com/term/ai/clustering)
- [k-Nearest Neighbors (k-NN)](https://learn.benibix.com/term/ai/k-nearest-neighbors)
- [Unsupervised Learning](https://learn.benibix.com/term/ai/unsupervised-learning)

## Told apart from

- [k-Means vs k-Nearest Neighbors](https://learn.benibix.com/compare/k-means-vs-k-nearest-neighbors): Both have a k and both measure closeness, so people often swap them. They do different jobs. In k-means, k is how many groups to find in data with no labels. In k-nearest neighbors, k is how many labelled neighbours vote on a new example's group.

## Taught in

- [Clustering and PCA](https://learn.benibix.com/learn/ai-machine-learning/clustering-and-pca): Machine Learning, 11/18

![Grey dots on the left. On the right the same dots fall into three groups, each with a cross at its centre.](https://learn.benibix.com/diagrams/ml-clustering.svg)

---

Source: https://learn.benibix.com/term/ai/k-means-clustering
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
