Fast hierarchical clustering routines for R and Python. Provides efficient implementations of hierarchical clustering (e.g., single, complete, average linkage) with memory-saving algorithms. Current version 1.3.0, with an irregular release cadence (last release 2022).
pip install fastclusterVerified import paths — ran on the pinned version, not inferred.
Basic usage: create random data, compute linkage matrix using average method.
Use method='ward' for Ward linkage. If you need weighted or centroid methods, note they may differ from scipy.
Use scipy.spatial.distance.squareform to convert square matrix to condensed form before passing to linkage().
Use scipy.cluster.hierarchy.linkage with method='centroid' or 'median' if you need exact scipy compatibility.
If you must use precomputed distances with Ward linkage, use scipy.cluster.hierarchy.linkage with method='ward' after ensuring distances are Euclidean squared.
Run 'pip install fastcluster' to install the package.
Convert square matrix to condensed form: from scipy.spatial.distance import squareform; condensed = squareform(square_matrix).
Ensure input array is contiguous and dtype is float64. Try X = np.ascontiguousarray(X, dtype=np.float64).