2015-11-08 113 views
2

我需要使用Java中的回归预测结束sem标记。这是我迄今为止Weka使用Java进行预测

public class LR{ 
    public static void main(String[] args) throws Exception 
    { 
     BufferedReader datafile = new BufferedReader(new FileReader("C:\\dataset.arff")); 
     Instances data = new Instances(datafile); 

     data.setClassIndex(data.numAttributes()-1); //setting class attribute 
     datafile.close(); 

     LinearRegression lr = new LinearRegression(); //build model 
     int folds=10; 

     Evaluation eval = new Evaluation(data); 
     eval.crossValidateModel(lr, data, folds, new Random(1)); 
     System.out.println(eval.toSummaryString()); 

     //save the model 
     weka.core.SerializationHelper.write("C:\\lr.model", lr); 

     //load the model 
     Classifier cls = (Classifier)weka.core.SerializationHelper.read("C:\\lr.model"); 

    } 
} 

如何使用所加载的模型来预测它们在另一个文件中的学生的痕迹:"testfile"

回答

0

将其他文件加载为Weka实例,迭代每个实例并调用cls.classifyInstance

参见This example

+0

我正在一个误差为行双clsLabel = cls.classifyInstance(unlabeled.instance(I));我找不到错误 – user5538704

+0

@ user5538704使用调试器 –