我正在尝试从 Java 中的多维数组获取 arrf 扩展输出文件。我导入了weka库,但是出现错误; The type FastVector<E> is deprecated.
我可以用什么代替 FastVector 以及如何重写下面的代码?
import weka.core.FastVector; //Error: The type FastVector<E> is deprecated.
int [][] myArray = new int[45194][12541];
for (int i = 0; i < myArray.length; i++) {
for (int j = 0; j < myArray[0].length; j++) {
System.out.print(myArray[i][j]+" ");
}
System.out.println("");
}
int numAtts = myArray[0].length;
FastVector atts = new FastVector(numAtts);
for (int att = 0; att < numAtts; att++) {
atts.addElement(new Attribute("Attribute" + att, att));
}
int numInstances = myArray.length;
Instances dataset = new Instances("Dataset", atts, numInstances);
for (int inst = 0; inst < numInstances; inst++) {
dataset.add(new Instance(1.0, myArray[inst])); //Error: Cannot instantiate the type Instance
}
BufferedWriter writer = new BufferedWriter(new FileWriter("test.arff"));
writer.write(dataset.toString());
writer.flush();
writer.close();
最佳答案
Weka 现在大多数地方都使用类型化的 ArrayLists。您可以为此使用 ArrayList<Attribute>
:
ArrayList<Attribute> atts = new ArrayList<Attribute>();
for (int att = 0; att < numAtts; att++) {
atts.add(new Attribute("Attribute" + att, att));
}
关于java - 不推荐使用FastVector <E>类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26878103/