GroupedKFold implements CrossValidator<GroupedDataset<KEY, ListDataset<INSTANCE>, INSTANCE>> { @Override public CrossValidationIterable<GroupedDataset<KEY, ListDataset<INSTANCE>, INSTANCE>> createIterable( GroupedDataset<KEY, ListDataset<INSTANCE>, INSTANCE> data) { return new GroupedKFoldIterable(data, k); } GroupedKFold(int k); @Override CrossValidationIterable<GroupedDataset<KEY, ListDataset<INSTANCE>, INSTANCE>> createIterable(
			GroupedDataset<KEY, ListDataset<INSTANCE>, INSTANCE> data); @Override String toString();  }
@Test public void testEqual30() { final GroupedKFold<String, Integer> cv = new GroupedKFold<String, Integer>(30); final CrossValidationIterable<GroupedDataset<String, ListDataset<Integer>, Integer>> iterable = cv .createIterable(equalDataset); assertEquals(30, iterable.numberIterations()); for (final ValidationData<GroupedDataset<String, ListDataset<Integer>, Integer>> cvData : iterable) { final GroupedDataset<String, ListDataset<Integer>, Integer> training = cvData.getTrainingDataset(); final GroupedDataset<String, ListDataset<Integer>, Integer> validation = cvData.getValidationDataset(); assertEquals(1, validation.numInstances()); assertEquals(equalDataset.numInstances() - 1, training.numInstances()); assertEquals(equalDataset.numInstances(), validation.numInstances() + training.numInstances()); } }
@Test public void testEqual10() { final GroupedKFold<String, Integer> cv = new GroupedKFold<String, Integer>(10); final CrossValidationIterable<GroupedDataset<String, ListDataset<Integer>, Integer>> iterable = cv .createIterable(equalDataset); assertEquals(10, iterable.numberIterations()); for (final ValidationData<GroupedDataset<String, ListDataset<Integer>, Integer>> cvData : iterable) { final GroupedDataset<String, ListDataset<Integer>, Integer> training = cvData.getTrainingDataset(); final GroupedDataset<String, ListDataset<Integer>, Integer> validation = cvData.getValidationDataset(); assertEquals(3, validation.numInstances()); assertEquals(equalDataset.numInstances() - 3, training.numInstances()); assertEquals(equalDataset.numInstances(), validation.numInstances() + training.numInstances()); } }