小编典典
这是加载模型以预测实例值的示例。示例模型是在Weka Explorer中创建并保存的J48决策树。它是根据Weka提供的名义天气数据构建的。它称为“
tree.model”。
//load model
String rootPath="/some/where/";
Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath+"tree.model");
//predict instance class values
Instances originalTrain= //load or create Instances to predict
//which instance to predict class value
int s1=0;
//perform your prediction
double value=cls.classifyInstance(originalTrain.instance(s1));
//get the name of the class value
String prediction=originalTrain.classAttribute().value((int)value);
System.out.println("The predicted value of instance "+
Integer.toString(s1)+
": "+prediction);
输出是:
The predicted value of instance 0: no
Weka api和序列化的入门者资源非常丰富!
2020-10-20