public static < I , O > CrossValidationEvaluation < I , O > kFold ( Collection < Example < I , O > > data , int k ) { Preconditions . checkNotNull ( data ) ; Preconditions . checkArgument ( k > 1 ) ; int numTrainingPoints = data . size ( ) ; List < Collection < Example < I , O > > > folds = Lists . newArrayList ( ) ; for ( List < Example < I , O > > fold : Iterables . partition ( data , ( int ) Math . ceil ( numTrainingPoints / k ) ) ) { folds . add ( fold ) ; } return new CrossValidationEvaluation < I , O > ( folds ) ; }
Construct a cross validation evaluation from a data set by partitioning it into k folds . The elements in data should be in a random order .