Cluster Analysis: First Intuition¶
Why this matters¶
The full Cluster Analysis lesson introduces k-means, hierarchical clustering, DBSCAN, centroids, dendrograms, density, and text clustering.
This page gives the basic idea first:
Clustering is useful when you do not already know the categories. Instead of training on known answers, you ask the data a more open-ended question:
Mental model¶
Imagine a small cafe wants to understand its customers.
| customer | visits_per_month | average_spend | buys_lunch |
|---|---|---|---|
| A | 2 | 6 | no |
| B | 9 | 14 | yes |
| C | 8 | 13 | yes |
| D | 1 | 5 | no |
| E | 10 | 30 | yes |
| F | 3 | 28 | no |
There is no column that says:
Clustering tries to discover useful groups from the available features.
For example, the cafe might find:
Those names do not come from the algorithm automatically. A person still has to inspect the clusters and decide what they mean.
Core ideas¶
- Clustering is used when the answer labels are missing or ignored.
- An observation is one row or example.
- A feature is one input column used for grouping.
- A cluster is a group of observations that are similar according to the chosen features.
- Similarity depends on representation: changing the features can change the clusters.
- Many clustering methods use distance, meaning how far apart observations are in feature space.
- Feature scaling matters because large-numbered features can dominate distance.
- Cluster labels such as
0,1, and2are arbitrary names, not real-world categories. - Different algorithms define "group" differently.
Walkthrough¶
Start with rows and features¶
In the cafe table, each customer is one observation.
The columns are possible features:
If we cluster using only visits_per_month and average_spend, the algorithm only knows those two facts about each customer.
It does not know why a customer visits, whether they live nearby, what they buy, or whether they are happy.
That is the first important boundary:
Clustering is not classification¶
In classification, the training data includes known answers.
Example:
In clustering, the known answer is not provided.
Example:
The algorithm may return labels like this:
But 0, 1, and 2 are just names. They do not mean "bad customer," "good customer," or "lunch customer" until you inspect the rows in each group.
Similarity depends on the features¶
Suppose customer E and customer F both spend a lot:
| customer | visits_per_month | average_spend | buys_lunch |
|---|---|---|---|
| E | 10 | 30 | yes |
| F | 3 | 28 | no |
If we focus mostly on spend, they look similar.
If we focus on visit frequency and lunch buying, they look less similar.
That means clustering does not discover groups in a vacuum. It discovers groups in the representation you choose.
Plain version:
Distance means how far apart rows are¶
Many clustering methods imagine each row as a point on a chart.
With two numeric features, the cafe data can be imagined like this:
Customers close together on that chart are treated as more similar.
Customers far apart are treated as less similar.
You do not need the distance formula yet. For this bridge, use the plain meaning:
Scaling can change what "nearby" means¶
Distance-based clustering is sensitive to numeric scale.
In the cafe example:
The spend numbers are larger. If the algorithm uses raw numbers, average_spend may have more influence than visits_per_month.
That might be what you want.
But it might also be an accident caused by units:
Feature scaling puts numeric features on more comparable ranges before distance is used.
The key idea:
Different algorithms mean different ideas of a group¶
The full lesson introduces three clustering approaches.
You do not need the mechanics yet. Start with the basic questions each one asks.
k-means:
Can we represent each group by a center point?
hierarchical clustering:
Which rows or groups should be merged step by step?
DBSCAN:
Where are the dense neighborhoods, and which points look isolated?
These methods can disagree because they define "group" differently.
That is normal. Clustering usually does not have one guaranteed correct answer.
Term Decoder¶
| Term | Friendly meaning |
|---|---|
| observation | one row or example |
| feature | one input column used for grouping |
| label | a known answer or category |
| cluster | a group found by the algorithm |
| cluster label | an arbitrary name such as 0, 1, or 2 |
| feature space | the chart-like space created by the chosen features |
| distance | how far apart rows are in feature space |
| scaling | putting numeric features on comparable ranges |
| centroid | center point representing a cluster |
| density | how many points are packed into a nearby area |
| noise | a point DBSCAN does not attach to a cluster |
Common traps¶
Clusters are not automatically real-world categories
The algorithm returns groups. A person still has to inspect them and decide whether the groups are meaningful.
Cluster labels are just names
Cluster 0 is not better, earlier, or more real than cluster 1. The numbers are arbitrary identifiers.
Feature choice controls the question
If you cluster customers by spend, you answer a spend-based question. If you cluster by visits and lunch buying, you answer a different question.
Distance depends on scale
A feature with larger raw numbers can dominate distance unless features are scaled or deliberately weighted.
Different algorithms can find different groups
k-means, hierarchical clustering, and DBSCAN use different ideas of what a group is. Disagreement is evidence to inspect, not automatically an error.
Check yourself¶
What is clustering used for?
Finding groups in data when known answer labels are missing or not used.
In the cafe example, what is one observation?
One customer row.
Why are cluster labels like 0, 1, and 2 not real categories by themselves?
They are arbitrary names assigned by the algorithm. You need to inspect the rows in each cluster before giving the group a real-world meaning.
Why can changing the features change the clusters?
Features define what the algorithm can compare. Changing the features changes the meaning of similarity.
Why can scaling matter for clustering?
Distance-based methods can be dominated by features with larger numeric ranges.
What is the rough idea of k-means?
Group points around center points called centroids.
What is the rough idea of hierarchical clustering?
Build groups by merging rows or smaller groups step by step.
What is the rough idea of DBSCAN?
Find dense neighborhoods and mark isolated points as noise.
Next¶
Next: Cluster Analysis: k-Means in Code
When you read the practical code bridge and the full lesson, translate the main technical terms back to these ideas:
feature space -> the chart-like space made by chosen features
distance -> how far apart rows are
centroid -> a cluster center
inertia -> how tightly points sit around their centroids
dendrogram -> a tree showing merge order
density -> many nearby points
noise -> isolated point not attached to a dense cluster
Source anchors¶
- Supports:
study-guide/docs/lessons/08b-cluster-analysis-k-means-in-code.mdandstudy-guide/docs/lessons/08-cluster-analysis.md - Source file:
notebooks/Module2/08-Cluster Analysis.ipynb - Key source concepts prepared here: unsupervised learning, observations, features, labels, feature space, distance, feature scaling, cluster labels, centroids, hierarchical clustering, DBSCAN density, noise points