def boot_repeatability_test(): "boot index iterator test for repeatability" msg = "%s indices were not repeatable when n=%d and nboot=%d" n = 4 nboot = 3 train1 = [] test1 = [] randint = np.random.RandomState([1, 2, 3]).randint for train, test in bootstrap(n, nboot, randint): train1 += train test1 += test train2 = [] test2 = [] randint = np.random.RandomState([1, 2, 3]).randint for train, test in bootstrap(n, nboot, randint): train2 += train test2 += test yield assert_equal, train1, train2, msg % ('train', n, nboot)
def boot_count_test(): "boot index iterator test for proper count and uniqueness" msg1 = "Did not get number of training elements expected when " msg1 += "n=%d and nboot=%d" msg2 = "Same element in train and test when n=%d and nboot=%d" msg3 = "test is empty when n=%d and nboot=%d" msg4 = "There are not n unique elements in train and test " msg4 += "n=%d and nboot=%d" msg5 = "Min index value is not 0 when n=%d and nboot=%d" msg6 = "Max index value is not 0 when n=%d and nboot=%d" for n in range(2, 8): for nboot in range(2, n + 1): for train, test in bootstrap(n, nboot): yield assert_equal, len(train), n, msg1 % (n, nboot) ncommon = len(set(train) & set(test)) yield assert_equal, ncommon, 0, msg2 % (n, nboot) yield assert_, len(test) > 0, msg3 % (n, nboot) unique = set(train) | set(test) yield assert_equal, len(unique), n, msg4 % (n, nboot) yield assert_equal, min(unique), 0, msg5 % (n, nboot) yield assert_equal, max(unique), n - 1, msg6 % (n, nboot)
def boot_count_test(): "boot index iterator test for proper count and uniqueness" msg1 = "Did not get number of training elements expected when " msg1 += "n=%d and nboot=%d" msg2 = "Same element in train and test when n=%d and nboot=%d" msg3 = "test is empty when n=%d and nboot=%d" msg4 = "There are not n unique elements in train and test " msg4 += "n=%d and nboot=%d" msg5 = "Min index value is not 0 when n=%d and nboot=%d" msg6 = "Max index value is not 0 when n=%d and nboot=%d" for n in range(2, 8): for nboot in range(2, n+1): for train, test in bootstrap(n, nboot): yield assert_equal, len(train), n, msg1 % (n, nboot) ncommon = len(set(train) & set(test)) yield assert_equal, ncommon, 0, msg2 % (n, nboot) yield assert_, len(test) > 0, msg3 % (n, nboot) unique = set(train) | set(test) yield assert_equal, len(unique), n, msg4 % (n, nboot) yield assert_equal, min(unique), 0, msg5 % (n, nboot) yield assert_equal, max(unique), n-1, msg6 % (n, nboot)