Skip to content

Instantly share code, notes, and snippets.

@jetnew
Last active June 2, 2019 02:25
Show Gist options
  • Save jetnew/bd9cc4a2f548ea20596d825e682be880 to your computer and use it in GitHub Desktop.
Save jetnew/bd9cc4a2f548ea20596d825e682be880 to your computer and use it in GitHub Desktop.
Hierarchical Clustering using scikit-learn and scipy
from sklearn.cluster import AgglomerativeClustering
clusters = 3
y_pred = AgglomerativeClustering(n_clusters=clusters).fit_predict(X)
from scipy.cluster.hierarchy import linkage, fcluster, dendrogram
clusters=5
cls = linkage(X, method='ward')
y_pred = fcluster(cls, t=clusters, criterion='maxclust')
dendrogram(cls)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment