【问题标题】:Getting Xmeans clusterer output programmatically in Weka在 Weka 中以编程方式获取 Xmeans 聚类器输出
【发布时间】:2012-09-09 05:12:02
【问题描述】:

在 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 并没有看到类似的东西。

【问题讨论】:

    标签: cluster-analysis weka xmeans


    【解决方案1】:

    这是 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 的任何集群器的结果获取集群分配。

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 2018-01-27
      • 2021-09-30
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      相关资源
      最近更新 更多