Complete linkage merges clusters by considering the maximum distance between points in the two clusters. Single linkage uses the minimum distance, average linkage uses the average distance, and Ward linkage minimizes variance.
from scipy.cluster.hierarchy import linkage import numpy as np X = np.array([[1, 2], [3, 4], [5, 6]]) Z = linkage(X, method='single') print(Z)
The linkage matrix shows the clusters merged, the distance between them, and the number of original points in the new cluster. Single linkage uses the minimum distance between points in clusters.
Hierarchical clustering works well when clusters are not spherical and the number of clusters is unknown. K-means assumes spherical clusters and requires the number of clusters upfront. Hierarchical clustering is less efficient for very large datasets.
Manhattan distance sums absolute differences along each dimension, which can change how close points appear compared to Euclidean distance. This can lead to different cluster shapes and merges in hierarchical clustering.
A cophenetic correlation coefficient near 1 means the hierarchical clustering preserves the original pairwise distances well, indicating a good fit between the dendrogram and the data.
