First you need to load the file using an ArffReader
. Here's the standard way to do so from the Weka javadocs:
BufferedReader reader = new BufferedReader(new FileReader("file.arff"));
ArffReader arff = new ArffReader(reader);
Instances data = arff.getData();
data.setClassIndex(data.numAttributes() - 1);
Then you can use the Instances
object obtained above to iterate through each attribute and its associated values, printing as you go:
for (int i = 0; i < data.numAttributes(); i++)
{
// Print the current attribute.
System.out.print(data.attribute(i).name() + ": ");
// Print the values associated with the current attribute.
double[] values = data.attributeToDoubleArray(i);
System.out.println(Arrays.toString(values));
}
This will result in output like the following:
attribute1: [value1, value2, value3]
attribute2: [value1, value2, value3]