本文介绍了交叉验证-Weka API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Weka Api通过10倍交叉验证来建立分类模型?我问这个问题,因为每个交叉验证的运行都会创建一个新的分类模型.我应该在测试数据中使用Wich分类模型吗?

How can I make a classification model by 10-fold cross-validation using Weka Api? I ask this, because each cross-validation's run a new classification model is created. Wich classification model should I use in my test data?

谢谢!

推荐答案

如果根据所有训练数据构造分类器,则使用10倍交叉验证来获得分类器准确性的估算 .当感觉到没有足够的数据用于独立测试集时使用.这意味着您要在预测未来数据时根据所有训练数据构建新模型. 10倍交叉验证的结果是您对新分类器的效果的猜测.

10-fold cross validation is used to get an estimate of a classifier's accuracy should that classifier be constructed from all of the training data. It is used when it is felt that there is not enough data for an independent test set. This means that you should build a new model from all the training data when you go to predict future data. The result from 10-fold cross validation is a guess as to how well your new classifier should perform.

以下代码显示了通过API使用Weka交叉验证,然后从整个训练数据集中构建新模型的示例.

The following code shows an example of using Weka's cross-validation through the API, and then building a new model from the entirety of the training dataset.

    //Training instances are held in "originalTrain"

    Classifier c1 = new NaiveBayes();
    Evaluation eval = new Evaluation(originalTrain);
    eval.crossValidateModel(c1, originalTrain, 10, new Random(1));
    System.out.println("Estimated Accuracy: "+Double.toString(eval.pctCorrect()));

    //Train a new classifier
    Classifier c2 = new NaiveBayes();
    c2.buildClassifier(originalTrain)  //predict with this model

这篇关于交叉验证-Weka API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:45