문제

how is it possible to add a class attribute in a WEKA ARFF file by using Java?

In particular, my ARFF structure (according to what is stated here) should be:

@attribute text string
@attribute classifyIn {basketball,nonbasketball}

My question is: how to declare classifyIn programmatically?

My procedure:

I declared the ARFF attributes as follows:

FastVector attributes = new FastVector(2);

attributes.addElement(new Attribute("text", (FastVector) null));    

FastVector classes = new FastVector();
classes.addElement(className);
classes.addElement("non" + className);
attributes.addElement(new Attribute("class",classes));

and I am inserting entries as follows:

double[] newInst = new double[2];
newInst[0] = (double)data.attribute(0).addStringValue(textValue);
newInst[1] = (double)data.attribute(1).addStringValue(className);

where className is either the string basketball or the string nonbasketball.

The error:

However, when I run the code, the following error appears:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1

Here is a related question, which did not receive an answer.

도움이 되었습니까?

해결책

The code has to be modified in the following way:

newInst[1] = (double)data.attribute(1).indexOfValue(className);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top