def test_select_random_size_none(monkeypatch): # Monkeypatch so we know that random returns monkeypatch.setattr(random, 'randint', lambda x, y: 0) # randint always returns 0 input_matrix, target_matrix = datasets.get_xor() new_inp_matrix, new_tar_matrix = base.select_random( input_matrix, target_matrix) assert new_inp_matrix.shape == input_matrix.shape assert new_tar_matrix.shape == target_matrix.shape for inp_vec in new_inp_matrix: assert (inp_vec == input_matrix[0]).all() # due to monkeypatch for tar_vec in new_tar_matrix: assert (tar_vec == target_matrix[0]).all() # due to monkeypatch
def test_select_random_size_none(seed_random): # Default to size smaller than number of samples input_matrix, target_matrix = datasets.get_random_classification( 1000, 1, 2) new_inp_matrix, new_tar_matrix = base.select_random( input_matrix, target_matrix) assert len(new_inp_matrix) < len(input_matrix) assert len(new_inp_matrix) == base._selection_size_heuristic( len(input_matrix)) assert len(new_tar_matrix) < len(input_matrix) assert len(new_tar_matrix) == base._selection_size_heuristic( len(input_matrix))
def test_select_random_size_none_few_samples(monkeypatch): # When number of samples is low, default to all samples # Monkeypatch so we know that random returns # randint always returns 0 monkeypatch.setattr(random, 'randint', lambda x, y: 0) input_matrix, target_matrix = datasets.get_xor() new_inp_matrix, new_tar_matrix = base.select_random( input_matrix, target_matrix) assert new_inp_matrix.shape == input_matrix.shape assert new_tar_matrix.shape == target_matrix.shape for inp_vec in new_inp_matrix: assert (inp_vec == input_matrix[0]).all() # Due to monkeypatch for tar_vec in new_tar_matrix: assert (tar_vec == target_matrix[0]).all() # Due to monkeypatch
def test_select_random(monkeypatch): # Monkeypatch so we know that random returns # randint always returns 0 monkeypatch.setattr(random, 'randint', lambda x, y: 0) input_matrix, target_matrix = datasets.get_xor() # Test size param new_inp_matrix, new_tar_matrix = base.select_random(input_matrix, target_matrix, size=2) assert new_inp_matrix.shape[0] == 2 assert new_tar_matrix.shape[0] == 2 for inp_vec in new_inp_matrix: assert (inp_vec == input_matrix[0]).all() # Due to monkeypatch for tar_vec in new_tar_matrix: assert (tar_vec == target_matrix[0]).all() # Due to monkeypatch