【问题标题】:How to display standard deviation values by using Evaluation class of WEKA with Java Code如何使用带有 Java 代码的 WEKA 评估类来显示标准差值
【发布时间】:2014-03-07 22:17:13
【问题描述】:

我正在编写一个 WEKA 分类器。我使用了评估类 (http://weka.sourceforge.net/doc.dev/weka/classifiers/Evaluation.html) 的 toSummaryString()、toMatrixString 和 toClassDetailString 方法来显示结果。结果显示正确。但是,我想显示每个结果的标准偏差值,因为它们是通过使用 WEKA 的实验者 GUI 显示的。我怎样才能做到这一点 ?

【问题讨论】:

标签: java machine-learning classification weka


【解决方案1】:

要获得标准差,您需要使用Experiment 类,然后获得统计信息。这是一个示例:Using the Experiment API

【讨论】:

    【解决方案2】:

    您可以使用以下代码:

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

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 2019-11-29
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 2015-03-02
      • 1970-01-01
      • 2016-08-22
      相关资源
      最近更新 更多