Package org.encog.ml.data.cross

Examples of org.encog.ml.data.cross.KFoldCrossvalidation


   * @param k The number of folds.
   * @param shuffle True if we should shuffle.
   * @return The trained method.
   */
  public MLMethod crossvalidate(int k, boolean shuffle) {
    KFoldCrossvalidation cross = new KFoldCrossvalidation(
        this.trainingDataset, k);
    cross.process(shuffle);

    int foldNumber = 0;
    for (DataFold fold : cross.getFolds()) {
      foldNumber++;
      report.report(k, foldNumber, "Fold #" + foldNumber);
      fitFold(k, foldNumber, fold);
    }

    double sum = 0;
    double bestScore = Double.POSITIVE_INFINITY;
    MLMethod bestMethod = null;
    for (DataFold fold : cross.getFolds()) {
      sum += fold.getScore();
      if (fold.getScore() < bestScore) {
        bestScore = fold.getScore();
        bestMethod = fold.getMethod();
      }
    }
    sum = sum / cross.getFolds().size();
    report.report(k, k, "Cross-validated score:" + sum);
    return bestMethod;
  }
View Full Code Here

TOP

Related Classes of org.encog.ml.data.cross.KFoldCrossvalidation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.