Example usage for weka.classifiers.evaluation Evaluation crossValidateModel

List of usage examples for weka.classifiers.evaluation Evaluation crossValidateModel

Introduction

In this page you can find the example usage for weka.classifiers.evaluation Evaluation crossValidateModel.

Prototype

public void crossValidateModel(Classifier classifier, Instances data, int numFolds, Random random)
        throws Exception 

Source Link

Document

Performs a (stratified if class is nominal) cross-validation for a classifier on a set of instances.

Usage

From source file:gate.plugin.learningframework.engines.EngineWeka.java

@Override
public Object evaluateXVal(InstanceList instances, int k, String parms) {
    Parms opts = new Parms(parms, "s:seed:i", "S:nostratify:b");
    int seed = (int) opts.getValueOrElse("seed", 0);
    boolean noStratify = (boolean) opts.getValueOrElse("nostratify", 0);
    Random rand = new Random(seed);
    Instances all = new CorpusRepresentationWeka(corpusRepresentationMallet).getRepresentationWeka();
    Evaluation eval = null;
    try {/*from   w  ww  . j  a v a 2s.co m*/
        eval = new Evaluation(all);
    } catch (Exception ex) {
        throw new GateRuntimeException("Could not create evaluation object", ex);
    }
    Classifier classifier = (Classifier) trainer;
    try {
        eval.crossValidateModel(classifier, all, k, rand);
    } catch (Exception ex) {
        throw new GateRuntimeException("Error running cross validation", ex);
    }
    System.out.println("Crossvaliation evaluation result:\n" + eval);
    return eval;
}