Week 6: Unsupervised Learning | Machine Learning Course
WEEK 6
Unsupervised Learning
Clustering, dimensionality reduction, and real-world applications
What is Unsupervised Learning?
In supervised learning, we teach a computer with labeled examples — like a teacher showing
a student the right answers. In unsupervised learning, we give the computer data with no
labels and ask it to find patterns completely on its own.
REAL-LIFE ANALOGY
Imagine you empty a big toy box onto the floor and ask a 5-year-old to tidy it up — without telling
them the rules. They might naturally group all the cars together, all the Lego bricks together, and all
the teddy bears together. Nobody told them how — they figured it out themselves. That is
unsupervised learning!
Topic 1: Clustering
Clustering is the task of grouping data points together so that points in the same group (called a
cluster) are more similar to each other than to points in other groups.
K-Means Clustering
K-Means groups data into K number of clusters. The algorithm assigns each data point to the
nearest group centre, then keeps adjusting until the groups are as tight and well-separated as
possible. You must decide the value of K before starting.
REAL-LIFE ANALOGY
Imagine you and your friends are at a market and want to split into 3 teams to cover different sections.
Everyone walks toward the team leader closest to them. The leaders then move to the middle of their
group. People re-shuffle. You keep doing this until no one wants to move anymore. That is K-Means!
How K-Means works — step by step:
1. Choose K — decide how many groups you want (e.g. K = 3)
2. Place K random centre points (called centroids) in your data
3. Assign every data point to its nearest centroid
4. Move each centroid to the average position of all points in its group
5. Repeat steps 3 and 4 until nothing changes anymore
Page 1 of 4
Week 6: Unsupervised Learning | Machine Learning Course
Key properties of K-Means:
• Simple and fast — works well for large datasets
• You must choose K in advance — this can be tricky
• Works best with round, evenly sized clusters
• Results can vary between runs (random initialisation)
Hierarchical Clustering
Hierarchical clustering builds a tree of clusters — starting by treating every single data point as
its own group, then merging the closest groups step by step until everything is one big group.
You can cut the tree at any level to get your desired number of clusters.
REAL-LIFE ANALOGY
Think about a family tree — you have individuals, then siblings, then cousins, then the whole
extended family under one grandparent. Hierarchical clustering builds this kind of tree for your data,
showing which data points are most similar and which are only loosely related.
Two approaches:
Agglomerative (bottom-up) Divisive (top-down)
Start: every point is its own group. Start: everyone is in one big group.
Keep merging the two closest clusters. Keep splitting groups apart.
Stop when all are merged into one. End: every point is alone.
Most commonly used approach. Less common but used in specific cases.
The Dendrogram:
The result of hierarchical clustering is visualised as a dendrogram — a diagram that looks like
an upside-down tree. It shows how data points were grouped together at each step. The height
of each branch tells you how different those groups are from each other.
Key properties of Hierarchical Clustering:
• No need to choose K before starting
• Produces the same result every time (deterministic)
• Visual and easy to interpret via the dendrogram
• Slower and more memory-intensive for large datasets
K-Means vs Hierarchical — Quick Comparison
K-Means Hierarchical
Page 2 of 4
Week 6: Unsupervised Learning | Machine Learning Course
Fast and scalable Slower on large data
Must choose K in advance No K needed upfront
Results can vary between runs Deterministic — same result always
Better for large datasets Shows full relationship tree
Best with round-shaped clusters Works with any cluster shape
Topic 2: Dimensionality Reduction — PCA
Real datasets often have hundreds of features (columns). Dimensionality reduction
compresses this information into fewer dimensions while keeping as much of the important
pattern as possible.
Principal Component Analysis (PCA)
PCA is the most popular dimensionality reduction technique. It finds new directions in the data
— called principal components — that capture the most variation (spread) in the data. By
projecting data onto these new axes, we get a simpler representation.
REAL-LIFE ANALOGY
Imagine describing a person to a friend. You could list 100 things: exact height, weight, shoe size, hair
length, and so on. Or you could say 'they are tall and slim.' PCA does the same thing — it finds the 2
or 3 most important descriptions (called Principal Components) that capture most of what makes each
data point unique.
How PCA works — step by step:
6. Find the direction in the data where there is the most spread (variation)
7. That direction becomes your first principal component (PC1)
8. Find the next direction with most variation, perpendicular to PC1 — that is PC2
9. Keep going for PC3, PC4... but usually 2 to 3 components explain most of the data
10. Drop the remaining components — your data is now simpler but still meaningful!
Key concepts in PCA:
Principal Component A new direction (axis) that captures the most variance in the data. PC1
captures the most, PC2 the second-most, and so on.
Variance Explained Each component captures a percentage of total information. If PC1 + PC2
explain 85%, you have kept most of the story.
Eigenvectors The directions (axes) of the new space. Think of them as new rulers for
measuring your data in a more informative way.
Eigenvalues Tell you how much variance each direction captures. A bigger eigenvalue
Page 3 of 4
Week 6: Unsupervised Learning | Machine Learning Course
means a more important component.
Benefits and trade-offs of PCA:
• Reduces noise in the data
• Helps visualise high-dimensional data in 2D or 3D
• Speeds up other machine learning algorithms
• Some information is lost — it is a compression, not a perfect copy
Topic 3: Applications of Unsupervised Learning
Unsupervised learning techniques are used across many industries. Here are six major real-
world applications:
Customer segmentation Anomaly / fraud detection
Shops cluster customers by shopping habits to Banks find fraud by spotting transactions that do
send the right offers to the right people. K-Means not fit into any normal cluster — they stand
is widely used here. suspiciously alone.
Image compression Recommendation systems
PCA compresses photo files by keeping only the Netflix and Spotify find users with similar tastes
most important pixel patterns — smaller file size, via clustering, then recommend what similar
similar visual quality. users enjoyed.
Genetics and biology Document grouping
Researchers use hierarchical clustering to group News articles are automatically grouped by topic
genes that behave similarly, helping discover — sports, politics, tech — without anyone
disease patterns. manually labelling them.
Week 6 — Key Takeaways
• Unsupervised learning finds hidden patterns in data with no labels provided
• K-Means splits data into K groups by minimising distance to group centres
• Hierarchical clustering builds a tree of groupings visualised as a dendrogram
• PCA reduces many features into a few key components, simplifying data without losing
too much information
• These techniques power customer segmentation, fraud detection, recommendation
engines, genetics research, and more
Page 4 of 4