我正在通过IKVM使用Weka库,我已经为SMO构建了一个带Weka资源管理器的模型。现在我想用它来预测代码中未标记的数据(我已经用J48成功完成了)。
我加载了这样的模型:
weka.classifiers.functions.SMO smo = (weka.classifiers.functions.SMO)SerializationHelper.read("C:\\Users\\lorenzov\\Desktop\\weka_files\\Modelli\\SMO_modello.model");
此代码适用于J48:
weka.core.Instances test = new weka.core.Instances(new java.io.FileReader("C:\\Users\\lorenzov\\Desktop\\weka_files\\test.arff"));
test.setClassIndex(5);
// istanze da etichettare
Instances labeled = new Instances(test);
const int percentSplit = 66;
int trainSize = test.numInstances() * percentSplit / 100;
int testSize = test.numInstances() - trainSize;
weka.classifiers.evaluation.Evaluation eval = new weka.classifiers.evaluation.Evaluation(test);
eval.evaluateModel(cls, test);
eval.evaluateModel(cls, test);
for (int i = 0; i < test.numInstances(); i++)
{
weka.core.Instance currentInst = test.instance(i);
test.instance(i).classValue();
double predictedClass = cls.classifyInstance(currentInst);
labeled.instance(i).setClassValue(predictedClass);
}
如何使用SMO模型执行此操作?