
Clustering is one of the most important techniques in Unsupervised Machine Learning, allowing computers to discover hidden patterns and group similar data without using labeled examples. While K-Means Clustering is one of the most popular clustering algorithms, it requires you to decide the number of clusters before training.
Hierarchical Clustering solves this limitation by automatically building a hierarchy of clusters that can be visualized as a tree-like structure called a Dendrogram. This makes it easier to understand relationships between data points and decide the optimal number of clusters.
In this beginner-friendly guide, you’ll learn what Hierarchical Clustering is, its types, how it works, its advantages, disadvantages, and real-world applications. These concepts are covered in the Day 11 AI learning material.
What is Hierarchical Clustering?
Hierarchical Clustering is an Unsupervised Machine Learning technique used to group similar data points into clusters.
Unlike K-Means, you do not need to specify the number of clusters in advance. Instead, the algorithm builds a hierarchy of clusters that can later be visualized using a Dendrogram, a tree-like diagram showing how clusters are formed.
Why Use Hierarchical Clustering?
Hierarchical Clustering is useful because it:
- Does not require predefined cluster numbers.
- Shows relationships between clusters visually.
- Works well for small and medium-sized datasets.
- Helps discover natural groupings in data.
- Provides flexibility when choosing the final number of clusters.
Types of Hierarchical Clustering
There are two main types of Hierarchical Clustering.
1. Agglomerative Hierarchical Clustering (Bottom-Up)
Agglomerative clustering starts with each data point as its own individual cluster.
The algorithm repeatedly merges the two closest clusters until only one cluster remains.
This is the most commonly used type of Hierarchical Clustering.
2. Divisive Hierarchical Clustering (Top-Down)
Divisive clustering works in the opposite direction.
It starts with all data points grouped into a single cluster and repeatedly splits the cluster into smaller clusters until each data point becomes its own cluster or the desired number of clusters is reached.
How Does Agglomerative Hierarchical Clustering Work?
Agglomerative clustering follows a simple step-by-step process.
The presentation demonstrates this using four sample data points (A, B, C, and D) and shows how clusters are gradually merged based on their distances. The accompanying tables illustrate the distance calculations at each stage.
Step 1: Start with Individual Clusters
Initially, every data point is treated as its own cluster.
Example:
A B C D
Each point is independent.
Step 2: Calculate the Distance Matrix
Next, the algorithm calculates the distance between every pair of data points.
The presentation includes a distance matrix showing the distances among A, B, C, and D, which helps determine the closest clusters.
Step 3: Merge the Closest Clusters
The algorithm identifies the two closest clusters and merges them.
In the example, A and B are merged first because they have the smallest distance.
The presentation then recalculates distances between the new cluster {AB} and the remaining points using the minimum-distance approach.
Step 4: Find the Smallest Distance Again
After merging, the algorithm searches again for the smallest distance.
The presentation highlights a tie where:
- {AB} and C = 4
- C and D = 4
This demonstrates how the algorithm repeatedly compares cluster distances before deciding the next merge.
Step 5: Calculate New Cluster Distances
Distances between the newly formed clusters are calculated again.
The presentation shows how the distance between {AB} and {CD} is determined by taking the minimum distance between all possible point pairs, resulting in a minimum value of 4.
Step 6: Merge the Final Clusters
The algorithm continues merging until only one cluster remains.
This completes the hierarchical clustering process.
What is a Dendrogram?
A Dendrogram is a tree-like diagram that visually represents the order in which clusters are merged.
It allows you to:
- Observe how clusters are formed.
- Understand relationships between data points.
- Decide where to cut the tree to obtain the desired number of clusters.
The presentation introduces the dendrogram after demonstrating the agglomerative clustering process.
How Does Divisive Hierarchical Clustering Work?
Divisive clustering follows the opposite strategy.
The steps include:
- Start with one large cluster.
- Find the best way to split it.
- Split the left cluster.
- Split the right cluster.
- Continue until the desired clustering structure is achieved.
These steps are presented sequentially in the learning material.
Agglomerative vs Divisive Clustering

Advantages of Hierarchical Clustering
According to the presentation, Hierarchical Clustering offers several benefits:
- No need to specify the number of clusters in advance.
- Easy to visualize using dendrograms.
- Supports flexible cluster shapes.
- Does not require random initialization.
Disadvantages of Hierarchical Clustering
Despite its strengths, Hierarchical Clustering has some limitations.
The presentation lists the following disadvantages:
- High computational cost.
- Cannot undo previous merge or split decisions.
- Sensitive to outliers.
- Slow when working with large datasets.
Introduction to Density-Based Clustering
The presentation concludes with an introduction to DBSCAN (Density-Based Spatial Clustering of Applications with Noise).
DBSCAN is another unsupervised clustering algorithm that groups data points based on their density, making it useful for detecting clusters of varying shapes and identifying noise or outliers.
Real-World Applications of Hierarchical Clustering
Hierarchical Clustering is widely used in various industries, including:
- Customer Segmentation
- Document Organization
- Gene Expression Analysis
- Medical Research
- Image Segmentation
- Recommendation Systems
- Social Network Analysis
- Market Research
- Fraud Detection
Best Practices for Using Hierarchical Clustering
To achieve better clustering results:
- Normalize numerical features before clustering.
- Select an appropriate distance metric based on your dataset.
- Use dendrograms to determine the optimal number of clusters.
- Remove significant outliers before training.
- Apply Hierarchical Clustering to small and medium-sized datasets for better efficiency.
Hierarchical Clustering vs K-Means
