Cross Validation - Weka api

柔情痞子 提交于 2019-12-12 00:33:48

问题


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?

Thank you!!


回答1:


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.

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


来源:https://stackoverflow.com/questions/19167287/cross-validation-weka-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!