私はWEKA GUIを使用して生成し、WEKA JAVAコードで使用する予定のJ48モデルを用意しています。私はそのモデルを使用して、その場でデータを予測したいと思っています。次のように私のコード:My Weka Javaコード結果* WEKA * DUMMY * STRING * FOR * STRING *属性*
public static void dt(String type, String bitrate, String resolution, String fps, String duration){
String rootPath="/home/weka/Documents/";
Attribute attr1 = new Attribute("type", (FastVector) null);
Attribute attr2 = new Attribute("bitrate", (FastVector) null);
Attribute attr3 = new Attribute("resolution", (FastVector) null);
Attribute attr4 = new Attribute("fps", (FastVector) null);
Attribute attr5 = new Attribute("duration", (FastVector) null);
Attribute attr6 = new Attribute("class", (FastVector) null);
FastVector attributes = new FastVector();
attributes.addElement(attr1);
attributes.addElement(attr2);
attributes.addElement(attr3);
attributes.addElement(attr4);
attributes.addElement(attr5);
attributes.addElement(attr6);
Instances testing = new Instances("Test-dataset", attributes, 0);
testing.setClassIndex(testing.numAttributes() - 1);
double[] values = new double[testing.numAttributes()];
values[0] = testing.attribute(0).addStringValue(type);
values[1] = testing.attribute(1).addStringValue(bitrate);
values[2] = testing.attribute(2).addStringValue(resolution);
values[3] = testing.attribute(3).addStringValue(fps);
values[4] = testing.attribute(4).addStringValue(duration);
Instance inst = new Instance(1.0, values);
inst.setValue(testing.attribute(0), values[0]);
inst.setValue(testing.attribute(1), values[1]);
inst.setValue(testing.attribute(2), values[2]);
inst.setValue(testing.attribute(3), values[3]);
inst.setValue(testing.attribute(4), values[4]);
System.out.println("The instance: "+inst);
testing.add(inst);
try {
Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath+"multimedia.model");
double myValue = cls.classifyInstance(testing.lastInstance());
String prediction = testing.classAttribute().value((int) myValue);
System.out.println("The predicted value of the data = "+prediction);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
私のコードの結果:
==Service parameter information==
Service ID : 1
Type : audio
Bitrate : 96
Resolution : 0
FPS : 0
Duration : 20
The instance: 1,1,1,1,1,0
The predicted value of the data = *WEKA*DUMMY*STRING*FOR*STRING*ATTRIBUTES*
私の値は、インスタンスに含まれており、ウェカダミーメッセージを結果のなかったようです。私のコードはどこが間違っていますか?私は既にチュートリアルを検索し、その答えをグーグルではあるが、見つけられない。
ありがとうございます。
関連性のない**アトリビュート**オブジェクトを保持する配列/リストを作成する必要があります。命名項目a1、a2、..は常にあなたが何か間違っていることを示す良い指標です。あなたは、それらの属性がすでにリストに入っていれば、attributes.addElementを6回呼び出す必要はありません。 – GhostCat