Unsupervised Learning: Clustering with k-Means
So far in this course every lesson gave the computer labeled examples: emails already marked spam or not spam, houses with their known price, photos already tagged cat or dog. The machine simply learned to copy the answer key. But most of the data in the real world arrives with no answer key at all. Nobody has told you which customers are alike, which news stories belong together, or which colors dominate a photo. This lesson is about teaching a machine to find that hidden structure on its own. That whole family of methods is called unsupervised learning, and the most famous member of the family is a clustering algorithm called k-means.
By the end you will be able to run k-means by hand on paper, pick a sensible number of groups, know exactly where the algorithm breaks, and call it in a few lines of Python.
Your learning goals
- Explain what unsupervised learning is and how it differs from supervised learning.
- Describe what clustering does and name four real jobs it is used for.
- Trace the four steps of k-means by hand on a tiny 2D dataset, with real numbers.
- Choose the number of clusters $k$ using the elbow method and inertia.
- List k-means' main limitations (shape, scaling, initialization, choosing $k$).
- Contrast clustering vs classification and preview two other unsupervised ideas.
- Run
KMeansin scikit-learn and read back the cluster centers.
1. Learning without labels: the big idea
In supervised learning you hand the machine pairs of (input, correct answer). The word supervised means a "supervisor" already knows the right answer and is grading the machine's guesses. Classification and regression both work this way.