我使用weka kmeans分类器,我已经建立了一个模型。现在我想对每个质心的中心值进行聚类。我在weka UI上得到它
Attribute Full Data 0 1
(48836) (39469) (9367)
============================================
tt 428.6238 514.1345 68.3143
如何使用weka java jar获得它?
My weka聚类训练集只有一个属性。
要获取属性名,我这样做:String attname =clusterCenters.get(0).attribute(0).name();
如何获取集群中心值?
当你调用SimpleKMeans
中的getClusterCentroids()
方法时,你会得到一个Instances
对象(在weka-3-6-8中)。这是一组代表集群中心的实例(每个指定的集群一个实例)。
SimpleKMeans kmeans = ...
// your code
...
Instances instances = kmeans.getClusterCentroids();
一旦我们有了一组实例(质心),我们可以通过numInstances()
猜测它的大小,使用instance(int index)
迭代它们,并通过double value(int attIndex)
获得它们的值:
for ( int i = 0; i < instances.numInstances(); i++ ) {
// for each cluster center
Instance inst = instances.instance( i );
// as you mentioned, you only had 1 attribute
// but you can iterate through the different attributes
double value = inst.value( 0 );
System.out.println( "Value for centroid " + i + ": " + value );
}
就是这些。我没有编译代码,但我就是这么做的。