2021年4月27日星期二

Counting the number of instances from Attribute

I'm trying to count the number of instances from a specific attribute in a .arff file. Although, I can only seem to select the attributes and not the values from the data where it appears.

In this case, I'm trying to select the number of times Wins appear in the data, however, the code only selects for the value Wins in the attribute.

Here's what I'm using:

//create the class to load the data  package weka;    import weka.core.Instances;  import weka.core.converters.ConverterUtils.DataSource;    public class DatasetLoading {      public static Instances loadData(String location) {      try {        return DataSource.read(location);      }      catch (Exception e) {        System.err.println("Failed to load data from: " + location);        e.printStackTrace();        return null;      }    }      public static void main(String[] args) {      String dataLocation = "C:/Users/Emil/Downloads/Week 1/Arsenal_TRAIN1.arff";      Instances train = loadData(dataLocation);      System.out.println(train);    }  }    //select for counts of values that appear in the data    public class test_learning {  public static void main(String[] args) throws Exception {      String arff = "C:/Users/Emil/Downloads/Week 1/Arsenal_TRAIN1.arff";      Instances data = DatasetLoading.loadData(arff);      System.out.print("Num of Wins = " + data.attribute(2).value(2));    

Output: Num of Wins = Win

Expected:

Output: Num of Wins = 12

Example of datafile:

@relation Arsenal-weka.filters.unsupervised.attribute.Remove-R3    @attribute Leno {0,1}  @attribute Tierney {0,1}  @attribute class {Loss,Draw,Win}    @data  1,0,Loss  1,0,Loss  0,1,Draw  1,0,Draw  0,0,Win  0,1,Win  1,1,Win  0,1,Win  1,1,Win  1,0,Win  1,1,Loss  0,1,Draw  1,1,Draw  1,1,Draw  0,0,Win  1,0,Win  0,1,Win  1,1,Win  1,1,Win  1,1,Win  
https://stackoverflow.com/questions/67288606/counting-the-number-of-instances-from-attribute April 28, 2021 at 02:20AM

没有评论:

发表评论