通过wekapythonwrapp集群后如何确定每个实例的集群分配

2024-06-28 20:37:58 发布

您现在位置:Python中文网/ 问答频道 /正文

from weka.clusterers import Clusterer

clusterer = Clusterer(classname="weka.clusterers.SimpleKMeans", options=["-N", "6"])
clusterer.build_clusterer(data)

这就是聚类

在这之后,我想知道每个实例。如何我们能做到吗??在


Tags: 实例fromimportbuilddata聚类optionsweka
1条回答
网友
1楼 · 发布于 2024-06-28 20:37:58

您可以使用cluster_instance(Instance)方法来获取从0开始的集群索引,或者使用distribution_for_instance(Instance)方法来获得集群分布:

for inst in data:
    cl = clusterer.cluster_instance(inst)
    dist = clusterer.distribution_for_instance(inst)
    print("cluster=" + str(cl) + ", distribution=" + str(dist))

相关问题 更多 >