1

私はwekaデータセットを持っています:

@attribute uid numeric
@attribute itemid numeric
@attribute rating numeric
@attribute timestamp numeric

@data
196 242 3   881250949
186 302 3   891717742
22  377 1   878887116
196 51  5   881250949
244 51  2   880606923

次のように新しいインスタンスを追加したい場合:

244 59  2   880606923

どうすればできますか?

このようなもの ?

Instances newData = arffLoader.getDataSet();
    for (int i = 0; i < newData.numInstances(); i++) {
         Instance one = newData.instance(i);
         one.setDataset(data);
         data.add(one);
    }
4

3 に答える 3

0

次のように、arff ファイルに新しい行を追加するだけです。

String filename= "MyDataset.arff";
FileWriter fwriter = new FileWriter(filename,true); //true will append the new instance
fwiter.write("244 59  2   880606923\n");//appends the string to the file
fwriter.close();
于 2013-06-03T12:14:43.533 に答える
-2

新しいインスタンスは、次のように既存のデータセットに簡単に追加できます。

 //assuming we already have arff loaded in a variable called dataset
     Instance newInstance  = new Instance();
     for(int i = 0 ; i < dataset.numAttributes() ; i++)
     {

         newInstance.setValue(i , value);
         //i is the index of attribute
         //value is the value that you want to set
     }
     //add the new instance to the main dataset at the last position
     dataset.add(newInstance);
     //repeat as necessary
于 2014-03-03T05:41:02.140 に答える