Linkage Functions

In hierarchical clustering, once you know the distance between individual points, you need a rule for deciding the distance between entire clusters of points - that rule is called a linkage function.

Single Linkage

Defines the distance between two clusters as the distance between their closest pair of points. It tends to produce long, "chained" clusters and is sensitive to noise and outliers.

Complete Linkage

Defines the distance between two clusters as the distance between their farthest pair of points. This produces more compact, evenly-sized clusters compared to single linkage.

Average Linkage

Takes the average distance between all pairs of points across the two clusters, offering a balance between the extremes of single and complete linkage.

Ward's Linkage

Merges the pair of clusters that leads to the smallest possible increase in total within-cluster variance. It's one of the most popular choices because it tends to create clusters of similar size.

Implementing in Python

from scipy.cluster.hierarchy import linkage

Z = linkage(data, method="ward")
print(Z[:5])
The choice of linkage function can significantly change your clustering results - it's a good idea to try more than one method and compare the resulting dendrograms before finalizing your clusters.

Coming Up Next

Now that you understand how clusters get merged, it's time to visualize that process using a dendrogram.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course