首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WEKA交叉验证线性回归-我能得到RMSPE吗?

WEKA交叉验证线性回归-我能得到RMSPE吗?
EN

Stack Overflow用户
提问于 2021-03-08 04:37:21
回答 1查看 126关注 0票数 0

是否有可能在交叉验证模型后得到RMSPE?我看到我可以很容易地得到RMSE --但是的均方根百分比错误呢?

我将示例代码与WEKA线性回归交叉验证结合在一起:

代码语言:javascript
复制
        // loads data and set class index
        final ArrayList<Attribute> attributes = new ArrayList<>();
        attributes.add(new Attribute("x"));
        attributes.add(new Attribute("y"));

        Instances data = new Instances("name", attributes, 0);
        data.add(new DenseInstance(1d, new double[]{5, 80}));
        // ... add more data

        // -c last
        data.setClassIndex(data.numAttributes() - 1);

        // classifier
        final LinearRegression cls = new LinearRegression();

        // other options
        int seed = 129;
        int folds = 3;

        // randomize data
        Random rand = new Random(seed);
        Instances randData = new Instances(data);
        randData.randomize(rand);
        if (randData.classAttribute().isNominal())
            randData.stratify(folds);

        // perform cross-validation
        Evaluation eval = new Evaluation(data);

        eval.crossValidateModel(cls, data, 3, new Random(seed));

        System.out.println("rootMeanSquaredError " + eval.rootMeanSquaredError());
        System.out.println("rootRelativeSquaredError " + eval.rootRelativeSquaredError());
        System.out.println("rootMeanPriorSquaredError " + eval.rootMeanPriorSquaredError());

        // output evaluation
        System.out.println();
        System.out.println("=== Setup ===");
        System.out.println("Classifier: " + cls.getClass().getName() + " " + Utils.joinOptions(cls.getOptions()));
        System.out.println("Dataset: " + data.relationName());
        System.out.println("Folds: " + folds);
        System.out.println("Seed: " + seed);
        System.out.println();
        System.out.println(eval.toSummaryString("=== " + folds + "-fold Cross-validation ===", true));


        /*

        === Setup ===
        Classifier: weka.classifiers.functions.LinearRegression -S 0 -R 1.0E-8 -num-decimal-places 4
        Dataset: name
        Folds: 3
        Seed: 129

        === 3-fold Cross-validation ===
        Correlation coefficient                  0.6289
        Mean absolute error                      7.5177
        Root mean squared error                  8.262
        Relative absolute error                 85.7748 %
        Root relative squared error             77.9819 %
        Total Number of Instances               15

         */
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-13 01:54:37

默认情况下,Weka不计算RMSPE。我已经为数值类(NB:只做了有限的测试)设置了一个名为rmspe包的小Weka包。

在运行评估之后(安装了该包),您应该能够按如下方式检索统计数据:

代码语言:javascript
复制
Evaluation eval = ... // initialize your evaluation object
...                   // perform your evaluation
double rmspe = eval.getPluginMetric("weka.classifiers.evaluation.RMSPE").getStatistic("RMSPE");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66524370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档