@Test public void testCrossValidation() { DataModelIF<Long, Long> dm = DataModelFactory.getDefaultModel(); for (long u = 1L; u <= USERS; u++) { for (long i = 1L; i <= ITEMS; i++) { dm.addPreference(u, i, 1.0 * u * i); } } int nFolds = 5; DataModelIF<Long, Long>[] splits = null; splits = new CrossValidationSplitter<Long, Long>(nFolds, false, 1L).split(dm); assertTrue(splits.length == 2 * nFolds); Long userTest = -1L; Long itemTest = -1L; for (Long user : splits[1].getUsers()) { userTest = user; for (Long item : splits[1].getUserItems(userTest)) { itemTest = item; break; } break; } assertTrue((splits[0].getUserItems(userTest) == null) || (Double.isNaN(splits[0].getUserItemPreference(userTest, itemTest)))); for (int i = 1; i < splits.length / 2; i++) { DataModelIF<Long, Long> training = splits[2 * i]; DataModelIF<Long, Long> test = splits[2 * i + 1]; assertTrue((test.getUserItems(userTest) == null) || (Double.isNaN(test.getUserItemPreference(userTest, itemTest)))); assertTrue(!Double.isNaN(training.getUserItemPreference(userTest, itemTest))); } }
private Split() { }
Split { private Split() { } }
Split { private Split() { } private  Split(); }
Split { private Split() { } private  Split(); static void main(final String[] args); }
Split { private Split() { } private  Split(); static void main(final String[] args);  }