Agglomerative Clustering and Dendrogram Visualization using Scikit-Learn
Experiment
Agglomerative Clustering and Dendrogram Visualization using Scikit-Learn
๐ฏ Objective
To implement Agglomerative Hierarchical Clustering using scikit-learn and visualize the clustering using a dendrogram.
๐ Theory
๐น Hierarchical Clustering
Hierarchical clustering creates a tree-like structure of clusters:
- Agglomerative (Bottom-Up) → merges closest clusters step-by-step
๐น Agglomerative Clustering in Scikit-Learn
The class AgglomerativeClustering:
- Does not require manual distance computation
-
Supports linkage methods:
-
single -
complete -
average -
ward(default)
-
๐น Linkage Methods
| Method | Description |
|---|---|
| Single | Minimum distance |
| Complete | Maximum distance |
| Average | Mean distance |
| Ward | Minimizes variance |
๐น Dendrogram
- Visual representation of cluster merging
- Height = distance between clusters
- Helps decide number of clusters
๐งพ Sample Dataset
| Point | X | Y |
|---|---|---|
| A | 1 | 1 |
| B | 2 | 1 |
| C | 4 | 3 |
| D | 5 | 4 |
| E | 8 | 7 |
๐ป Program (Python Code)
๐ Output
๐น Cluster Labels (Example)
๐น Cluster Interpretation
- Cluster 1 → A, B, C, D
- Cluster 2 → C,D
- Cluster 3 → E
๐น Dendrogram
- Shows merging sequence:
- A + B
- C + D
- (AB) + (CD)
- (ABCD) + E
๐ Result
Agglomerative clustering was successfully performed using scikit-learn, and the hierarchical structure was visualized using a dendrogram.
- Library implementation simplifies clustering
- Dendrogram provides clear visualization
- Results match manual implementation


Comments
Post a Comment