如何使用 Java 在 WEKA ARFF 文件中添加类属性?
特别是,我的 ARFF 结构(根据所述 here )应该是:
@attribute text string
@attribute classifyIn {basketball,nonbasketball}
我的问题是:如何以编程方式声明 classifyIn
?
我的程序:
我声明 ARFF 属性如下:
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));
我将插入条目如下:
double[] newInst = new double[2];
newInst[0] = (double)data.attribute(0).addStringValue(textValue);
newInst[1] = (double)data.attribute(1).addStringValue(className);
其中 className
是字符串 basketball
或字符串 nonbasketball
。
错误:
但是,当我运行代码时,出现以下错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
Here是一个相关问题,但没有收到答案。
最佳答案
代码必须按以下方式修改:
newInst[1] = (double)data.attribute(1).indexOfValue(className);
关于java - ARFF 文件中的类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23337674/