シリアル化された分類子を使用して新しいインスタンスを分類したいと考えています。このクラスを見つけましたが、理解できません。
arg[2]
= クラス属性名およびarg[3]
= 元のデータセットから予測するインスタンスの 1 ベースのインデックス
このクラスのコードは次のとおりです。
import weka.core.*;
import weka.classifiers.*;
import java.io.*;
/**
* A little class for testing deserialization and prediction.
*
* @author FracPete (fracpet at waikat dot ac dot nz)
*/
public class Blah {
/**
* Takes 4 arguments:
* <ol>
* <li>serialized model</li>
* <li>ARFF file</li>
* <li>class attribute name</li>
* <li>1-based index of an instance to predict from original dataset</li>
* </ol>
*/
public static void main(String[] args) throws Exception {
// read the arff training file
BufferedReader reader = new BufferedReader(new FileReader(args[1]));
Instances in = new Instances(reader);
in.setClass(in.attribute(args[2]));
// instance to classify
int index = Integer.parseInt(args[3]) - 1;
Instance toClassifyInstance = (Instance) in.instance(index).copy();
toClassifyInstance.setClassValue(Instance.missingValue());
// deserialize model
Classifier cls = null;
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args[0]));
cls = (Classifier) ois.readObject();
ois.close();
// PREDICTION
double clsLabel = cls.classifyInstance(toClassifyInstance);
String classLabel = in.classAttribute().value((int) clsLabel);
System.out.println(classLabel + " =?= " + in.instance(index).stringValue(in.classIndex()));
}
}
前もって感謝します。