如何用Java代码使用WEKA评估类显示标准偏差值

如何用Java代码使用WEKA评估类显示标准偏差值,java,machine-learning,classification,weka,Java,Machine Learning,Classification,Weka,我正在写一个WEKA分类器。我使用了求值类()的方法toSummaryString()、toTrixString和toClassDetailString来显示结果。结果显示正确。但是,我想显示每个结果的标准偏差值,正如使用WEKA的实验者GUI显示的那样。我该怎么做 要获得标准偏差,您需要使用实验类,然后获得统计数据。下面是一个示例:。您可以使用以下代码: package weka.api; //import required classes import weka.experiment.Sta

我正在写一个WEKA分类器。我使用了求值类()的方法toSummaryString()、toTrixString和toClassDetailString来显示结果。结果显示正确。但是,我想显示每个结果的标准偏差值,正如使用WEKA的实验者GUI显示的那样。我该怎么做

要获得标准偏差,您需要使用
实验
类,然后获得统计数据。下面是一个示例:。

您可以使用以下代码:

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 );
            }

    }


    }
}
包weka.api;
//导入必需的类
导入weka.experience.Stats;
导入weka.core.AttributeStats;
导入weka.core.Instance;
导入weka.core.Instances;
导入weka.core.ConverterUtils.DataSource;
公共类服装{
公共静态void main(字符串args[])引发异常{
//加载数据集
数据源=新数据源(“D:/y.arff”);
//获取实例对象
实例数据=source.getDataSet();
//将类索引..设置为最后一个属性
if(data.classIndex()=-1){
data.setClassIndex(data.numAttributes()-1);
}
//获取属性数(注意不计算类)
int numAttr=data.numAttributes()-1;
对于(int i=0;i
这提供了一些见解