【问题标题】:Weka Prediction with Java使用 Java 进行 Weka 预测
【发布时间】:2015-11-09 04:52:17
【问题描述】:

我需要使用 Java 中的回归来预测结束 sem 标记。这就是我目前所拥有的

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"

【问题讨论】:

    标签: java weka


    【解决方案1】:

    将另一个文件加载为 Weka 实例,遍历每个实例并调用 cls.classifyInstance

    This example

    【讨论】:

    • 我收到了双 clsLabel = cls.classifyInstance(unlabeled.instance(i)); 行的错误我找不到错误
    • @user5538704 使用调试器
    猜你喜欢
    • 2015-03-07
    • 2017-12-07
    • 2013-04-22
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 2019-08-30
    • 2015-03-23
    • 1970-01-01
    相关资源
    最近更新 更多