'csv to arff and setclassindex

I have this csv

5.1,3.5,1.4,0.2,0
4.9,3,1.4,0.2,0
4.6,3.1,1.5,0.2,0
...............

I read csv in weka java and convert it to arff. I set the class (last field) with setClassIndex. In the arff file the 5th field is set @attribute att5 numeric, it should be @attribute class 0. Why ? Is it correct ?

@relation 1

@attribute att1 numeric
@attribute att2 numeric
@attribute att3 numeric
@attribute att4 numeric
@attribute att5 numeric

@data
5.1,3.5,1.4,0.2,0
4.9,3,1.4,0.2,0
4.6,3.1,1.5,0.2,0
..........

Here the java code :

loader.setSource(csvFiles);
Instances data = loader.getDataSet();
data.setClassIndex(data.numAttributes() - 1);
ArffSaver saver = new ArffSaver();
saver.setInstances(data);
saver.setFile(new File(filePath, "my.arff"));
saver.writeBatch();


Solution 1:[1]

The setClassIndex method only tells the dataset which attribute is acting as the class attribute. It doesn't change the dataset structure. Algorithms then check which attribute is the class attribute and act accordingly.

Any attribute (of any type) in a dataset can function as class attribute.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fracpete