예제 #1
0
def test_frienemy_safe_region():
    ds_test = DS(create_pool_classifiers(), safe_k=3)
    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    ds_test.neighbors = np.array([0, 1, 2, 6, 7, 8, 14])
    result = ds_test._frienemy_pruning()
    assert np.array_equal(result, np.array([[1, 1, 1]]))
예제 #2
0
def test_frienemy_not_all_classifiers_crosses():
    ds_test = DS(create_pool_classifiers(), safe_k=3)
    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    ds_test.neighbors = neighbors_ex1[0, :]
    result = ds_test._frienemy_pruning()
    assert np.array_equal(result, np.array([[1, 1, 0]]))
예제 #3
0
def test_frienemy_all_classifiers_crosses(index):
    ds_test = DS(create_pool_classifiers())
    ds_test.processed_dsel = dsel_processed_all_ones
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    ds_test.neighbors = neighbors_ex1[index, :]
    result = ds_test._frienemy_pruning()
    assert result.all() == 1.0
예제 #4
0
def test_frienemy_not_all_classifiers_crosses_batch():
    expected = np.array([[1, 1, 0], [0, 1, 0], [1, 1, 1]])
    ds_test = DS(create_pool_classifiers(), safe_k=3)
    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    # passing three samples to compute the DFP at the same time
    ds_test.neighbors = neighbors_ex1
    result = ds_test._frienemy_pruning()
    assert np.array_equal(result, expected)
예제 #5
0
def test_DFP_is_used():
    query = np.atleast_2d([1, 0])
    ds_test = DS(create_pool_classifiers(), DFP=True, safe_k=3)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    ds_test.neighbors = neighbors_ex1[0, :]
    ds_test.distances = distances_ex1[0, :]
    ds_test.classify_with_ds = MagicMock(return_value=0)
    ds_test.predict(query)
    assert np.array_equal(ds_test.DFP_mask, np.atleast_2d([1, 1, 0]))
예제 #6
0
def test_frienemy_safe_region_batch():
    n_samples = 10
    n_classifiers = 3
    expected = np.ones((n_samples, n_classifiers))
    ds_test = DS(create_pool_classifiers(), safe_k=3)
    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    ds_test.neighbors = np.tile(np.array([0, 1, 2, 6, 7, 8, 14]),
                                (n_samples, 1))
    result = ds_test._frienemy_pruning()

    assert np.array_equal(result, expected)
예제 #7
0
def test_predict_proba_DFP():
    query = np.atleast_2d([1, 1])
    ds_test = DS(create_pool_classifiers(), DFP=True, safe_k=3)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)

    # change the state of the system
    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1
    ds_test.neighbors = neighbors_ex1[0, :]
    ds_test.distances = distances_ex1[0, :]

    ds_test.predict_proba_instance = MagicMock(return_value=np.atleast_2d([0.25, 0.75]))
    ds_test.predict_proba(query)
    assert np.array_equal(ds_test.DFP_mask, np.array([1, 1, 0]))
예제 #8
0
def test_IH_is_used(index, expected):
    query = np.atleast_2d([1, 0])
    ds_test = DS(create_pool_classifiers(), with_IH=True, IH_rate=0.5)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)

    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1

    ds_test.neighbors = neighbors_ex1[index, :]
    ds_test.distances = distances_ex1[index, :]

    predicted = ds_test.predict(query)

    assert predicted == expected
예제 #9
0
def test_IH_is_used():
    expected = [0, 0, 1]
    query = np.ones((3, 2))
    ds_test = DS(create_pool_classifiers(), with_IH=True, IH_rate=0.5)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)

    ds_test.processed_dsel = dsel_processed_ex1
    ds_test.DSEL_target = y_dsel_ex1
    ds_test.DSEL_data = X_dsel_ex1

    ds_test.neighbors = neighbors_ex1
    ds_test.distances = distances_ex1

    predicted = ds_test.predict(query)

    assert np.array_equal(predicted, expected)