1. Clustering and the k-means objective
Clustering groups unlabelled points so that points in the same cluster are similar and points in different clusters are not. It is unsupervised: there are no class labels.
k-means partitions points into clusters , each represented by its centroid (the mean of its points). It minimises the sum of squared errors (SSE, also called within-cluster sum of squares):
For a fixed cluster, the point that minimises the sum of squared Euclidean distances is the mean. This is why k-means uses the mean as the centre. (The point minimising the sum of absolute distances in 1-D is the median.)
Finding the global minimum of SSE is NP-hard in general, so k-means is a heuristic that reaches a local minimum.