def hierarchicalClustering(X,y,Maxclust, C, Method = 'single', Metric = 'euclidean'):
# Perform hierarchical/agglomerative clustering on data matrix
Z = linkage(X, method=Method, metric=Metric)
# Compute and display clusters by thresholding the dendrogram
cls = fcluster(Z, criterion='maxclust', t=Maxclust)
figure()
#clusterplot(X, cls.reshape(cls.shape[0],1), y=y)
clusterPlot(X, cls.reshape(cls.shape[0],1), Maxclust, C, y=y)
# Display dendrogram
max_display_levels=7
figure()
dendrogram(Z, truncate_mode='level', p=max_display_levels, color_threshold=0.5*np.max(Z[:,2]))
title("Dendrgram of the Hierarchical Clustering")
show()
methods.py 文件源码
python
阅读 33
收藏 0
点赞 0
评论 0
评论列表
文章目录