def test_frienemy_safe_region(): ds_test = BaseDS(create_pool_classifiers(), safe_k=3) ds_test.fit(X_dsel_ex1, y_dsel_ex1) ds_test.DSEL_processed_ = dsel_processed_ex1 result = ds_test._frienemy_pruning(np.array([0, 1, 2, 6, 7, 8, 14])) assert np.array_equal(result, np.array([[1, 1, 1]]))
def test_frienemy_not_all_classifiers_crosses(): ds_test = BaseDS(create_pool_classifiers(), safe_k=3) ds_test.fit(X_dsel_ex1, y_dsel_ex1) ds_test.DSEL_processed_ = dsel_processed_ex1 result = ds_test._frienemy_pruning(neighbors_ex1[0, :]) assert np.array_equal(result, np.array([[1, 1, 0]]))
def test_frienemy_all_classifiers_crosses(index): ds_test = BaseDS(create_pool_classifiers()) ds_test.fit(X_dsel_ex1, y_dsel_ex1) ds_test.DSEL_processed_ = dsel_processed_all_ones result = ds_test._frienemy_pruning(neighbors_ex1[index, :]) assert result.all() == 1.0
def test_frienemy_no_classifier_crosses(): X = X_dsel_ex1 y = y_dsel_ex1 ds_test = BaseDS(create_pool_classifiers()) ds_test.fit(X, y) mask = ds_test._frienemy_pruning(neighbors_ex1[0, :]) assert mask.shape == (1, 3) and np.allclose(mask, 1)
def test_DFP_is_used(example_estimate_competence, create_pool_classifiers): X, y, neighbors, _, dsel_processed, _ = example_estimate_competence ds_test = BaseDS(create_pool_classifiers, DFP=True, safe_k=3) ds_test.fit(X, y) ds_test.DSEL_processed_ = dsel_processed DFP_mask = ds_test._frienemy_pruning(neighbors[0, :]) assert np.array_equal(DFP_mask, np.atleast_2d([1, 1, 0]))
def test_frienemy_no_classifier_crosses(example_estimate_competence, create_pool_classifiers): X, y, neighbors = example_estimate_competence[0:3] ds_test = BaseDS(create_pool_classifiers) ds_test.fit(X, y) mask = ds_test._frienemy_pruning(neighbors[0, :]) assert mask.shape == (1, 3) and np.allclose(mask, 1)
def test_frienemy_safe_region(example_estimate_competence, create_pool_classifiers): X, y, _, _, dsel_processed, _ = example_estimate_competence ds_test = BaseDS(create_pool_classifiers, safe_k=3) ds_test.fit(X, y) ds_test.DSEL_processed_ = dsel_processed result = ds_test._frienemy_pruning(np.array([0, 1, 2, 6, 7, 8, 14])) assert np.array_equal(result, np.array([[1, 1, 1]]))
def test_frienemy_all_classifiers_crosses(index, example_all_ones, create_pool_classifiers): X, y, neighbors, _, dsel_processed, _ = example_all_ones ds_test = BaseDS(create_pool_classifiers) ds_test.fit(X, y) ds_test.DSEL_processed_ = dsel_processed result = ds_test._frienemy_pruning(neighbors[index, :]) assert result.all() == 1.0
def test_DFP_is_used(): ds_test = BaseDS(create_pool_classifiers(), DFP=True, safe_k=3) ds_test.fit(X_dsel_ex1, y_dsel_ex1) ds_test.DSEL_processed_ = dsel_processed_ex1 ds_test.DSEL_target_ = y_dsel_ex1 ds_test.DSEL_data_ = X_dsel_ex1 DFP_mask = ds_test._frienemy_pruning(neighbors_ex1[0, :]) assert np.array_equal(DFP_mask, np.atleast_2d([1, 1, 0]))
def test_frienemy_not_all_classifiers_crosses_batch(): expected = np.array([[1, 1, 0], [0, 1, 0], [1, 1, 1]]) ds_test = BaseDS(create_pool_classifiers(), safe_k=3) ds_test.fit(X_dsel_ex1, y_dsel_ex1) ds_test.DSEL_processed_ = dsel_processed_ex1 # passing three samples to compute the DFP at the same time result = ds_test._frienemy_pruning(neighbors_ex1) assert np.array_equal(result, expected)
def test_frienemy_not_all_classifiers_crosses(example_estimate_competence, create_pool_classifiers): expected = np.array([[1, 1, 0], [0, 1, 0], [1, 1, 1]]) X, y, neighbors, _, dsel_processed, _ = example_estimate_competence ds_test = BaseDS(create_pool_classifiers, safe_k=3) ds_test.fit(X, y) ds_test.DSEL_processed_ = dsel_processed # passing three samples to compute the DFP at the same time result = ds_test._frienemy_pruning(neighbors) assert np.array_equal(result, expected)
def test_frienemy_safe_region_batch(): n_samples = 10 n_classifiers = 3 expected = np.ones((n_samples, n_classifiers)) ds_test = BaseDS(create_pool_classifiers(), safe_k=3) ds_test.fit(X_dsel_ex1, y_dsel_ex1) ds_test.DSEL_processed_ = dsel_processed_ex1 neighbors = np.tile(np.array([0, 1, 2, 6, 7, 8, 14]), (n_samples, 1)) result = ds_test._frienemy_pruning(neighbors) assert np.array_equal(result, expected)
def test_frienemy_safe_region_batch(example_estimate_competence, create_pool_classifiers): X, y, neighbors, _, dsel_processed, _ = example_estimate_competence n_samples = 10 n_classifiers = 3 expected = np.ones((n_samples, n_classifiers)) ds_test = BaseDS(create_pool_classifiers, safe_k=3) ds_test.fit(X, y) ds_test.DSEL_processed_ = dsel_processed neighbors = np.tile(np.array([0, 1, 2, 6, 7, 8, 14]), (n_samples, 1)) result = ds_test._frienemy_pruning(neighbors) assert np.array_equal(result, expected)