from weka.clusterers import Clusterer
clusterer = Clusterer(classname="weka.clusterers.SimpleKMeans", options=["-N", "6"])
clusterer.build_clusterer(data)
this does the clustering
After this , I want to know the clustering assignment of each instance.How can we do that??
You can use the cluster_instance(Instance)
method to obtain the 0-based index of the cluster or the distribution_for_instance(Instance)
method to obtain the cluster distribution:
for inst in data:
cl = clusterer.cluster_instance(inst)
dist = clusterer.distribution_for_instance(inst)
print("cluster=" + str(cl) + ", distribution=" + str(dist))