public double doCrossValidation(Iterable<T> data,int dataSize) throws InterruptedException, ExecutionException {
  stats=new OneVariableStats();
  log.info("Starting cross validation at " + (new Date()));
  log.info("Splitting data into " + numFolds + " folds");
  List<List<T>> splits=splitData(data,dataSize);
  log.info("Splitting complete.");
  ExecutorService executor=Executors.newFixedThreadPool(numThreads);
  List<FutureTask<Double>> folds=new ArrayList<>();
  for (int i=0; i < numFolds; i++) {
    List<T> trainingSet=new ArrayList<>();
    for (int j=0; j < numFolds; j++) {
      if (j != i)       trainingSet.addAll(splits.get(j));
    }
    List<T> testSet=splits.get(i);
    FutureTask<Double> fold=createFoldTask(trainingSet,testSet,i);
    executor.execute(fold);
    folds.add(fold);
  }
  executor.shutdown();
  executor.awaitTermination(timeoutSeconds,TimeUnit.SECONDS);
  for (  FutureTask<Double> fold : folds) {
    stats.add(fold.get());
  }
  log.info("Cross validation complete at " + (new Date()));
  return stats.mean();
}

public double doCrossValidation ( Iterable < T > data , int dataSize ) throws InterruptedException , ExecutionException { stats = new OneVariableStats ( ) ; log . info ( "Starting cross validation at " + ( new Date ( ) ) ) ; log . info ( "Splitting data into " + numFolds + " folds" ) ; List < List < T > > splits = splitData ( data , dataSize ) ; log . info ( "Splitting complete." ) ; ExecutorService executor = Executors . newFixedThreadPool ( numThreads ) ; List < FutureTask < Double > > folds = new ArrayList < > ( ) ; for ( int i = 0 ; i < numFolds ; i ++ ) { List < T > trainingSet = new ArrayList < > ( ) ; for ( int j = 0 ; j < numFolds ; j ++ ) { if ( j != i ) trainingSet . addAll ( splits . get ( j ) ) ; } List < T > testSet = splits . get ( i ) ; FutureTask < Double > fold = createFoldTask ( trainingSet , testSet , i ) ; executor . execute ( fold ) ; folds . add ( fold ) ; } executor . shutdown ( ) ; executor . awaitTermination ( timeoutSeconds , TimeUnit . SECONDS ) ; for ( FutureTask < Double > fold : folds ) { stats . add ( fold . get ( ) ) ; } log . info ( "Cross validation complete at " + ( new Date ( ) ) ) ; return stats . mean ( ) ; }
note : this does not take care of shuffling or randomizing the data .
