gpt4 book ai didi

cluster-analysis - 在Weka中以编程方式获取Xmeans集群器输出

转载 作者:行者123 更新时间:2023-12-04 18:11:44 29 4
gpt4 key购买 nike

在Weka中使用Kmeans时,可以在模型的结果输出上调用getAssignments()以获取每个给定实例的集群分配。这是一个(截断的)Jython示例:

>>>import weka.clusterers.SimpleKMeans as kmeans
>>>kmeans.buildClusterer(data)
>>>assignments = kmeans.getAssignments()
>>>assignments
>>>array('i',[14, 16, 0, 0, 0, 0, 16,...])

每个群集号的索引对应于该实例。因此,实例0在群集14中,实例1在群集16中,依此类推。

我的问题是:Xmeans是否有类似的东西?我已经遍历了整个API here,但看不到任何类似信息。

最佳答案

这是来自Weka listserv的关于我的问题的回复:

 "Not as such. But all clusterers have a clusterInstance() method. You can 
pass each training instance through the trained clustering model to
obtain the cluster index for each."

这是我的Jython实现此建议的方法:
 >>> import java.io.FileReader as FileReader
>>> import weka.core.Instances as Instances
>>> import weka.clusterers.XMeans as xmeans
>>> import java.io.BufferedReader as read
>>> import java.io.FileReader
>>> import java.io.File
>>> read = read(FileReader("some arff file"))
>>> data = Instances(read)
>>> file = FileReader("some arff file")
>>> data = Instances(file)
>>> xmeans = xmeans()
>>> xmeans.setMaxNumClusters(100)
>>> xmeans.setMinNumClusters(2)
>>> xmeans.buildClusterer(data)# here's our model
>>> enumerated_instances = data.enumerateInstances() #get the index of each instance
>>> for index, instance in enumerate(enumerated_instances):
cluster_num = xmeans.clusterInstance(instance) #pass each instance through the model
print "instance # ",index,"is in cluster ", cluster_num #pretty print results

instance # 0 is in cluster 1
instance # 1 is in cluster 1
instance # 2 is in cluster 0
instance # 3 is in cluster 0

我将所有这些留作引用,因为可以使用相同的方法来为Weka的任何聚类器的结果获取聚类分配。

关于cluster-analysis - 在Weka中以编程方式获取Xmeans集群器输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12451591/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com