作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 weka kmeans 分类器,我已经为它构建了一个模型。现在我想对每个质心的中心值进行聚类。我在 weka UI 上获取它
Attribute Full Data 0 1
(48836) (39469) (9367)
============================================
tt 428.6238 514.1345 68.3143
如何使用 weka java jar 获取它?
我的 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 );
}
仅此而已。我没有编译代码,但我就是这样做的。
关于java - 如何获得weka簇质心的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14209625/
我是一名优秀的程序员,十分优秀!