Unsupervised learning and clustering
Not every dataset comes with answer labels. Unsupervised learning looks for structure in unlabeled data—and clustering groups similar items together, even when those groups do not match human categories.
Learning without answer labels.
In Lesson 4.1, you saw supervised learning, where each training example comes with a known target label (such as “spam” or “not spam”). Sometimes you have examples and their measurable details, but no target labels at all.
Imagine pouring a jar of mixed buttons onto a table with no category names written down. You can still sort them into piles by what looks alike—size, color, or number of holes—without anyone telling you what to call each pile.
Priya (an invented character for this lesson) has 12 books whose existing genre shelf stickers were peeled off. For each book, her checkout log only shows two numbers: page count and typical days kept.
Before we look at how a computer groups Priya’s books, here are the six terms this lesson uses in order:
Unsupervised learning: finding patterns in examples that have input features but no target answer labels.
Features: measurable details recorded for each example (recapped from Lessons 1.3 and 4.1)—here, pages and days kept.
Similarity: how close two examples are on the chosen features under a comparison rule (in this lab, straight-line distance after placing both features on a shared scale).
Clustering: an unsupervised method that aims to group examples so items in the same group are similar under a chosen distance rule.
Cluster: one unnamed group produced by clustering (such as Cluster 1, Cluster 2, or Cluster 3).
Human category (existing shelf label): a meaningful label people use for a real purpose, such as the library’s original genre shelves (Picture books, Cookbooks, or Novels).

How clustering groups data by similarity.
When each of Priya’s books is plotted by its two features—length in pages on the horizontal axis and typical days kept on the vertical axis—every book becomes a single dot. Clustering measures closeness between dots under a chosen distance rule and aims to put nearby dots into the same cluster.
Because pages (0–400) and days kept (0–20) use different units, our chart puts both features on a shared square scale so visual closeness matches feature closeness: 40 pages and 2 checkout days span the exact same distance.
1. Which features you choose
Changing the features changes what counts as “similar.” Grouping Priya’s books by pages and days kept could produce very different clusters than grouping them by publication year and cover price.
2. How many clusters you ask for
Many clustering methods ask you to choose the number of clusters ahead of time. Asking for 2, 3, or 4 groups can merge groups, split a tight group, or rearrange memberships across clusters.
Everyday example: A music app grouping unlabeled tracks by tempo and loudness may place a classical lullaby and a quiet acoustic folk song in the same cluster, because on those two audio features they sit right next to each other.
Group Priya’s books by similarity.
In the lab below, each dot is one of Priya’s 12 invented books plotted by pages and days kept. Each cluster preset shows the precomputed grouping with the smallest total squared distance from each book dot to its own cluster center (the average position of the dots in that group) on this square scale, and the shelf toggle lets you compare those unnamed clusters against the library’s existing genre shelves.
- Start on No groups, inspect the books (by sight on the plot or by tabbing through the book points with your keyboard), and decide which books you would group together.
- Click 3 clusters and compare the result with your guess—notice the groups are only named Cluster 1, Cluster 2, and Cluster 3.
- Try 2 clusters and 4 clusters to see how changing the requested count merges groups or splits the long-book group for these 12 books.
- Switch back to 3 clusters and click Reveal human shelves to see which real library shelves landed inside each cluster.
Square scale: 40 pages and 2 days kept span the same visual distance. Crosses (×) mark cluster centers.
Current view
Unlabeled view: 12 books plotted by pages and days kept, with no cluster assignments yet.
Selected book
- Title
- Kyoto Pocket Phrases
- Length
- 80 pages
- Typical checkout
- 3 days
- Cluster
- None yet
- Existing shelf
- Hidden
Simplified simulation: shows precomputed minimum squared-distance groupings (each dot to its cluster center) on 12 invented books rather than a live library database.
Why a cluster may not match a human category.
A common mistake is treating every cluster as a real-world category. Sometimes a cluster lines up closely with a useful human label, and other times it mixes items that people keep apart.
In Priya’s 3-cluster view, Cluster 1 groups four short books that readers return in 3 or 4 days. When you check the library’s existing shelves, that single cluster contains 2 Picture books, 1 Travel phrasebook, and 1 Poetry chapbook.
The clustering rule did not make a mistake—it only saw pages and days kept. Because it never saw what the books are about, a person still has to inspect the cluster and decide whether it is useful for a task (like setting loan periods) or not (like shelving by genre).

Everyday example: An online store clustering shoppers by visits per week and amount spent may put a one-time holiday gift buyer and a regular weekly grocery shopper in the same cluster—even though they need very different recommendations.
Where clustering helps—and its limits.
Clustering is most helpful when you are exploring unlabeled data: it can surface broad patterns, suggest starter groups for a person to review, or help you visually spot isolated points that sit far from every group. (Some clustering algorithms also explicitly flag outliers as ungrouped, whereas the lab above assigns all 12 books to a cluster.)
Keep three limits in mind: different features, scaling choices, or cluster counts can change the groups; clusters carry no built-in names; and real datasets often have borderline points sitting between groups.
- Does unsupervised learning mean zero human involvement?
No. People still choose which data and features to include, how to scale them, which settings (like cluster count) to try, and how to interpret the resulting groups.
- If I already have labeled categories to predict, should I use clustering?
Usually not. When you have known target labels and want to predict them for new examples, supervised classification (Lesson 4.3) is a more direct fit.
- Is clustering the only kind of unsupervised learning?
No. Clustering is one common approach; other unsupervised methods compress many features into fewer summaries or highlight unusual records.
Check your understanding.
Take this with you.
Clusters are similarity groups, not automatic categories. Unsupervised learning finds structure without answer labels, and clustering groups items that look close on the features and settings you chose. Always inspect what sits inside a cluster before naming or acting on it.
Ready to continue? Return to How Machines Learn.