我编写了一个简单的脚本,旨在对一个简单的测试数据集进行层次聚类。
我发现函数fclusterdata是将数据分为两个簇的候选函数。它需要两个必需的调用参数:数据集和阈值。 问题是,我找不到一个阈值来生成预期的两个集群。在
如果有人能告诉我我做错了什么,我会很高兴的。如果有人能指出更适合我的集群的其他方法,我也会很高兴(我明确地希望避免事先指定集群的数量)
这是我的代码:
import time
import scipy.cluster.hierarchy as hcluster
import numpy.random as random
import numpy
import pylab
pylab.ion()
data = random.randn(2,200)
data[:100,:100] += 10
for i in range(5,15):
thresh = i/10.
clusters = hcluster.fclusterdata(numpy.transpose(data), thresh)
pylab.scatter(*data[:,:], c=clusters)
pylab.axis("equal")
title = "threshold: %f, number of clusters: %d" % (thresh, len(set(clusters)))
print title
pylab.title(title)
pylab.draw()
time.sleep(0.5)
pylab.clf()
输出如下:
^{pr2}$
请注意,function reference有一个错误。
t
参数的正确定义是:“集群函数的截止阈值或最大集群数(criterian='maxclust')”。在所以试试这个:
相关问题 更多 >
编程相关推荐