使用scipy进行聚类

it2025-07-13  7

近期做图像的时候,突然有个idea,须要进行聚类,事实上算法非常easy,可是当时非常急。就直接使用了scipy的cluster。

使用起来事实上非常easy,可是中文的文章非常少,所以就简单的介绍一下。感兴趣的也能够自己去看一下英文的文档:http://docs.scipy.org/doc/scipy/reference/cluster.html。

这是我从stackoverflow看到的一个demo。假设仅仅是简单的使用cluster。这样就能够了。

import scipy import scipy.cluster.hierarchy as sch import matplotlib.pylab as plt scipy.randn(100,2) d = sch.distance.pdist(X) Z= sch.linkage(d,method='complete') P =sch.dendrogram(Z) plt.savefig('plot_dendrogram.png') T = sch.fcluster(Z, 0.5*d.max(), 'distance') #array([4, 5, 3, 2, 2, 3, 5, 2, 2, 5, 2, 2, 2, 3, 2, 3, 2, 5, 4, 5, 2, 5, 2, # 3, 3, 3, 1, 3, 4, 2, 2, 4, 2, 4, 3, 3, 2, 5, 5, 5, 3, 2, 2, 2, 5, 4, # 2, 4, 2, 2, 5, 5, 1, 2, 3, 2, 2, 5, 4, 2, 5, 4, 3, 5, 4, 4, 2, 2, 2, # 4, 2, 5, 2, 2, 3, 3, 2, 4, 5, 3, 4, 4, 2, 1, 5, 4, 2, 2, 5, 5, 2, 2, # 5, 5, 5, 4, 3, 3, 2, 4], dtype=int32) sch.leaders(Z,T) 假设想要了解很多其它一些的话,能够參考 http://nbviewer.ipython.org/github/herrfz/dataanalysis/blob/master/week4/clustering_example.ipynb

这篇文章事实上写的已经很棒了。尽管文件我没有可以成功down下来。

转载于:https://www.cnblogs.com/bhlsheji/p/5099844.html

相关资源:数据结构—成绩单生成器
最新回复(0)