Example #1
0
def test_estimate_competence(index, expected):
    query = np.atleast_2d([1, 1])

    des_p_test = DESP(create_pool_classifiers())
    des_p_test.fit(X_dsel_ex1, y_dsel_ex1)
    des_p_test.DFP_mask = np.ones(des_p_test.n_classifiers)
    des_p_test.neighbors = neighbors_ex1[index, :]
    des_p_test.distances = distances_ex1[index, :]
    competences = des_p_test.estimate_competence(query)
    assert np.isclose(competences, expected, atol=0.01).all()
Example #2
0
def test_estimate_competence_batch():
    query = np.ones((3, 2))
    expected = np.array([[0.57142857, 0.4285714, 0.57142857],
                         [0.71428571, 0.2857142, 0.71428571],
                         [0.2857142, 0.71428571, 0.2857142]])

    des_p_test = DESP(create_pool_classifiers())
    des_p_test.fit(X_dsel_ex1, y_dsel_ex1)
    neighbors = neighbors_ex1
    distances = distances_ex1
    competences = des_p_test.estimate_competence(query, neighbors, distances)
    assert np.allclose(competences, expected, atol=0.01)
Example #3
0
def test_estimate_competence_batch(example_estimate_competence,
                                   create_pool_classifiers):
    X, y, neighbors, distances, dsel_processed, _ = example_estimate_competence

    expected = np.array([[0.57142857, 0.4285714, 0.57142857],
                         [0.71428571, 0.2857142, 0.71428571],
                         [0.2857142, 0.71428571, 0.2857142]])

    des_p_test = DESP(create_pool_classifiers)
    des_p_test.fit(X, y)
    competences = des_p_test.estimate_competence(neighbors, distances)
    assert np.allclose(competences, expected, atol=0.01)
Example #4
0
def test_select_two_classes(index, expected):
    query = np.atleast_2d([1, 1])

    des_p_test = DESP(create_pool_classifiers())
    des_p_test.fit(X_dsel_ex1, y_dsel_ex1)

    neighbors = neighbors_ex1[index, :].reshape(1, -1)
    distances = distances_ex1[index, :].reshape(1, -1)

    competences = des_p_test.estimate_competence(query, neighbors, distances)
    selected = des_p_test.select(competences)

    assert np.array_equal(selected, expected)
Example #5
0
def test_select_two_classes(index, expected):
    query = np.atleast_2d([1, 1])

    des_p_test = DESP(create_pool_classifiers())
    des_p_test.fit(X_dsel_ex1, y_dsel_ex1)

    des_p_test.DFP_mask = np.ones(des_p_test.n_classifiers)
    des_p_test.neighbors = neighbors_ex1[index, :]
    des_p_test.distances = distances_ex1[index, :]

    competences = des_p_test.estimate_competence(query)
    selected = des_p_test.select(competences)

    assert selected == expected
Example #6
0
def test_select_three_classes(index, expected):
    query = np.atleast_2d([1, 1])

    des_p_test = DESP(create_pool_classifiers())
    des_p_test.fit(X_dsel_ex1, y_dsel_ex1)

    des_p_test.n_classes = 3
    des_p_test.neighbors = neighbors_ex1[index, :]
    des_p_test.distances = distances_ex1[index, :]

    competences = des_p_test.estimate_competence(query)
    selected = des_p_test.select(competences)

    assert np.array_equal(selected, expected)