无法创建新的输出文件。使用标准输出。将类标签添加到weka

时间:2017-12-06 07:54:43

标签: java jar weka arff

我使用GTZAN数据集中的jaudio提取了特征。 尝试使用java代码将类型类标签添加到arff文件。这是代码。

import java.io.*;

import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instances;
import weka.core.converters.ArffSaver;


public class AddAttribute
{
public static void main(String[] args) throws Exception
{
    if (args.length != 2) {
        System.out.println("\nUsage: java AddAttribute <file.arff> <genre>\n");
        System.exit(1);
    }
    String filename = args[0];
    String genre = args[1];

    // load dataset
    Instances data = new Instances(new BufferedReader(new FileReader(filename)));
    Instances newData = new Instances(data);
    // add new attribute        
    FastVector values = new FastVector();
    values.addElement("jazz");
    values.addElement("pop");
    values.addElement("metal");
    values.addElement("classical");
    Attribute genreAttr = new Attribute("Genre", values);
    newData.insertAttributeAt(genreAttr, newData.numAttributes());

    // add to each instance
    for (int i = 0; i < newData.numInstances(); i++) {
        newData.instance(i).setValue(newData.numAttributes() - 1, genre);
    }

    // save back to the original arff file
    ArffSaver saver = new ArffSaver();
    saver.setInstances(newData);
    saver.setFile(new File(filename));
    saver.writeBatch();
}
}

它会出现以下错误。 无法创建新的输出文件。使用标准输出。

0 个答案:

没有答案