def test_valid_selection_method(selection_method): X = np.random.rand(10, 2) y = np.ones(10) with pytest.raises(ValueError): dcs = BaseDCS(create_pool_classifiers(), selection_method=selection_method) dcs.fit(X, y)
def test_selection_method_type(selection_method, create_pool_classifiers): X = np.random.rand(10, 2) y = np.ones(10) with pytest.raises(TypeError): dcs = BaseDCS(create_pool_classifiers, selection_method=selection_method) dcs.fit(X, y)
def test_valid_diff_threshold_value(diff_thresh): X = np.random.rand(10, 2) y = np.ones(10) with pytest.raises(ValueError): dcs = BaseDCS(create_pool_classifiers(), selection_method='diff', diff_thresh=diff_thresh) dcs.fit(X, y)
def test_select_random(competences, expected): rng = np.random.RandomState(123456) pool_classifiers = create_pool_classifiers() dcs_test = BaseDCS(pool_classifiers, selection_method='random', random_state=rng) dcs_test.fit(X_dsel_ex1, y_dsel_ex1) selected_clf = dcs_test.select(np.array(competences)) assert np.allclose(selected_clf, expected)
def test_select_random_batch(): competences = np.array([[0.5, 0.5, 0.5], [0.8, 0.9, 1.0], [0.0, 0.10, 0.0]]) expected = np.array([1, 2, 1]) rng = np.random.RandomState(123456) pool_classifiers = create_pool_classifiers() dcs_test = BaseDCS(pool_classifiers, selection_method='random', random_state=rng) dcs_test.fit(X_dsel_ex1, y_dsel_ex1) selected_clf = dcs_test.select(competences) assert np.array_equal(selected_clf, expected)