gpt4 book ai didi

java - 如何获得weka簇质心的值(value)

转载 作者:搜寻专家 更新时间:2023-11-01 01:54:24 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com