java - CLI 中的 Weka 汇总统计数据

标签 java statistics weka decimal-point

如何在 Weka CLI(命令行)中使用汇总统计数据(均值、方差等)?

我知道有“AttributeStats”命令,但我应该如何编写代码?

例如,我有一个数据“D:\data.arff”,如何使用 CLI 编码找到每个变量的均值和方差?

最佳答案

经过长时间的搜索,我找到了这段代码,可以在Java中使用它来查找WEKA中变量的汇总统计信息。

package weka.api;
//import required classes
import weka.experiment.Stats;
import weka.core.AttributeStats;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

public class AttInst {
    public static void main(String args[]) throws Exception{
        //load dataset
        DataSource source = new DataSource("D:/y.arff");
        //get instances object 
        Instances data = source.getDataSet();
        //set class index .. as the last attribute
        if (data.classIndex() == -1) {
           data.setClassIndex(data.numAttributes() - 1);
        }
        //get number of attributes (notice class is not counted)
        int numAttr = data.numAttributes() - 1;
        for (int i = 0; i < numAttr; i++) {
            //check if current attr is of type nominal
            if (data.attribute(i).isNominal()) {
                System.out.println("The "+i+"th Attribute is Nominal"); 
                //get number of values
                int n = data.attribute(i).numValues();
                System.out.println("The "+i+"th Attribute has: "+n+" values");
            }           

            //get an AttributeStats object
            AttributeStats as = data.attributeStats(i);
            int dC = as.distinctCount;
            System.out.println("The "+i+"th Attribute has: "+dC+" distinct values");

            //get a Stats object from the AttributeStats
            if (data.attribute(i).isNumeric()){
                System.out.println("The "+i+"th Attribute is Numeric"); 
                Stats s = as.numericStats;
                System.out.println("The "+i+"th Attribute has min value: "+s.min+" and max value: "+s.max+" and mean value: "+s.mean+" and stdDev value: "+s.stdDev );
            }

    }


    }
}

关于java - CLI 中的 Weka 汇总统计数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33392547/

相关文章:

java - 频繁的对象属性访问是否会产生相关成本?

machine-learning - "vector augmented to 1"是什么意思?

api - Binance API 如何在 24 小时内计算 priceChangePercent

machine-learning - Biggram 中包含 weka 中的停用词?

machine-learning - Weka FilteredClassifier arrayOutOfBoundsException

java - Typescript 中的工厂模式并仅公开工厂类

java - 在 Spring Boot 应用程序中安排任务的最佳方法是什么

c++ - 计算大数的方差

在 Weka 中以编程方式使用 LibSVM 的 java 类路径错误

java - 如何防止 JInternalFrame 重新绘制重叠的 JInternalFrame