Reputation: 45
I am trying to learn Weka: I am using Iris data set from here http://storm.cis.fordham.edu/~gweiss/data-mining/weka-data/iris.arff
which has following fields
@RELATION iris
@ATTRIBUTE sepallength REAL
@ATTRIBUTE sepalwidth REAL
@ATTRIBUTE petallength REAL
@ATTRIBUTE petalwidth REAL
@ATTRIBUTE class {Iris-setosa,Iris-versicolor,Iris-virginica}
From this dataset I am trying extract the class labels from this data set, which is {Iris-setosa,Iris-versicolor,Iris-virginica}
I am not understanding how to get the class labels? Any references
public void getCdtion( String arff_path) throws Exception{
ArffLoader arffloder = new ArffLoader();
arffloder.setFile(new File(arff_path));
arffloder.getStructure();
Instances structure = arffloder.getDataSet();
System.out.println(arffloder.getStructure(););
}
Upvotes: 0
Views: 597
Reputation: 523
You are calling arffloader.getDataSet()
which returns the data set, not the header. The ARFF you provide in your question is just a header with no data in it. To get the class labels from the header, do the following.
public void getCdtion( String arff_path) throws Exception{
ArffLoader arffloder = new ArffLoader();
arffloder.setFile(new File(arff_path));
Instances structure = arffloder.getStructure();
Attribute classAtt = structure.classAttribute();
System.out.println(classAtt);
}
The class attribute classAtt
is an Attribute, see the link for more info.
Hope it helps!
Upvotes: 1