k-Means Clustering Algorithm
k-means can be viewed as a decomposition method in which each data point is represented by a single component.
Two Ways to Read the Same Algorithm
Most introductions present k-means as a method for sorting data into groups. That description is accurate, but it hides a second reading of the same algorithm. Instead of asking which group a point belongs to, you can ask how a point is described once the algorithm has finished. Seen this way, k-means is not only grouping data. It is also rewriting every data point in terms of something simpler. The name given to this rewriting is vector quantization.
What do you think happens?
Suppose the points 1.0 and 1.2 are each replaced by the center of their cluster, which is 1.1. What happens to the difference between 1.0 and 1.2?
Reveal answer
It disappears. Both points are now represented by 1.1, so the representation can no longer tell them apart.
Replacing each point with a single shared center means every point in a cluster gets the same description. The detail that separated those points is lost, which is the trade made by vector quantization.
Reading k-Means as a Decomposition
Earlier methods in this course describe data by building it up from parts. Principal component analysis, usually called PCA, looks for directions in which the data varies the most, chosen so that as much of the spread in the data as possible is captured. Non-negative matrix factorization, usually called NMF, looks for components that add together to make the data, and these components often correspond to extremes or recognizable parts of the data set rather than to averages.
Both approaches share a common pattern. Each data point is expressed as a combination of several components, and the point's identity comes from how those components are mixed together. k-means seems to have no components at all, so the natural question is whether it fits this same pattern. It does, once you look at what it hands back for each point.
k-means takes a different route. It tries to represent each data point using a cluster center. Where PCA and NMF build each point from several pieces, k-means assigns each point exactly one stand-in: the center of the cluster it belongs to. In other words, every point is described by a single component, and that component is the cluster center. The comparison below makes the contrast explicit.
| Method | How a data point is expressed | Components used per point |
|---|---|---|
| PCA | A combination of directions that capture as much of the spread as possible | Several |
| NMF | A sum of components that add together to make the data | Several |
| k-means | The single center of the cluster the point belongs to | Exactly one |
How each method expresses a data point, as described in the source
Vector Quantization and the Codebook
This is the central idea of vector quantization. Viewing k-means as a decomposition method means treating the set of cluster centers as a small vocabulary of components, with each data point being represented by one entry from that vocabulary. The point is not stored in full detail after clustering. It is replaced by the center that stands for its cluster.
Vector quantization is the representation of each data point by a single entry from a small set of vectors, where the entry used for a point is the center of the cluster that the point belongs to. The set of centers plays the role of a codebook.
The diagram below shows the codebook view. Each cluster center is a key in a small table, and the points it stands for are the values stored under that key. Because the table is small, the whole data set is described through a handful of entries rather than through every original value.
Tracing Four Points Through Quantization
Consider four one-dimensional values, 1.0, 1.2, 4.8, and 5.1, that k-means has grouped into two clusters with centers at 1.1 and 5.0. The example below is an illustration constructed for this article. It shows exactly what changes when each point is replaced by its center.
Quantizing four points with two centers
Points: 1.0, 1.2, 4.8, 5.1. Cluster centers: 1.1 and 5.0. Replace each point by the center of the cluster it belongs to, then describe what is lost.
- 1Match 1.0 to its center
1.0 is 0.1 away from 1.1 and 4.0 away from 5.0, so it belongs to the cluster centered at 1.1. Its description becomes 1.1.
- 2Match 1.2 to its center
1.2 is 0.1 away from 1.1 and 3.8 away from 5.0, so it also belongs to the cluster centered at 1.1. Its description becomes 1.1.
- 3Match 4.8 to its center
4.8 is 3.7 away from 1.1 and 0.2 away from 5.0, so it belongs to the cluster centered at 5.0. Its description becomes 5.0.
- 4Match 5.1 to its center
5.1 is 4.0 away from 1.1 and 0.1 away from 5.0, so it belongs to the cluster centered at 5.0. Its description becomes 5.0.
- 5Compare the two representations
Originally four distinct values. After quantization only two distinct values, 1.1 and 5.0, each used twice. The points 1.0 and 1.2 are no longer distinguishable, and neither are 4.8 and 5.1.
The quantized data is 1.1, 1.1, 5.0, 5.0. Each point is now described by one center, and the within-cluster differences are gone.
The outcome is the trade described earlier. The whole data set is now expressed through two centers instead of four distinct values. Each point still has a clear representative, but the small offsets from that representative, such as 1.0 being 0.1 below 1.1, are no longer stored.
Matching a Point to Its Center
The process for a single point has two stages. First, the point is compared against the cluster centers and matched to the one it belongs to. Second, the point's description is replaced by that center. The original point is not needed for the representation, because the center alone now carries its identity.
Read the map from left to right. Each position holds one original point, and the value stored there after quantization is the single center that point is assigned to. Every point has exactly one entry, which is what makes the representation a single-component description.
Mistakes Beginners Make with Quantization
Common mistake Assuming a quantized point keeps its original value
What it looks likeAfter quantization, 1.0 is represented as 1.1, not as 1.0.
Why it failsThe point's description is replaced by its cluster center, so the original value is no longer stored in the representation.
Do this insteadTreat the center as the point's only description after quantization, and remember that the original offset is lost.
Common mistake Thinking k-means uses several components per point, the way PCA or NMF do
What it looks likeDescribing 4.8 as a mix of 1.1 and 5.0 with weights.
Why it failsThe source states that vector quantization uses exactly one center per point, unlike PCA and NMF.
Do this insteadDescribe each point by the single center of its cluster.
Common mistake Believing the codebook loses no information because the centers are accurate
What it looks likeConcluding that 1.0 and 1.2 are still distinct because the centers are precise.
Why it failsPoints in the same cluster share a center, so their differences are discarded in the representation.
Do this insteadAccept that the compact representation trades within-cluster detail for compactness.
Practice: Quantize a New Point
Using the same two centers, 1.1 and 5.0, decide which center the new value 3.5 would be represented by under vector quantization, and state what the quantized representation of 3.5 would be. Then explain in one sentence what information about 3.5 is no longer stored.
Hints
- Compare the distance from 3.5 to 1.1 with the distance from 3.5 to 5.0.
- The quantized representation is the center itself, not the original value.
Key Takeaways
- k-means can be viewed as a decomposition method in which each data point is represented by a single component: the center of the cluster it belongs to.
- Unlike PCA and NMF, which express each point as a combination of several components, vector quantization uses exactly one center per point.
- Vector quantization treats the cluster centers as a small codebook, and each data point is replaced by one entry from that codebook.
- The quantized representation is compact because many points share a center, but it discards differences among points in the same cluster.