示例#1
0
def test_estimate_competence2(index, expected, example_estimate_competence):

    _, _, neighbors, distances, dsel_processed, _ = example_estimate_competence

    mcb_test = MCB()
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed

    neighbors = neighbors[index, :].reshape(1, -1)
    distances = distances[index, :].reshape(1, -1)
    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_DSEL_ = bks_dsel_ex2

    predictions = np.array([[0, 1, 0]])

    competences = mcb_test.estimate_competence(
        neighbors, distances=distances, predictions=np.atleast_2d(predictions))
    assert np.isclose(competences, expected).all()
示例#2
0
def test_estimate_competence(index, expected):
    query = np.atleast_2d([1, 1])

    mcb_test = MCB(create_pool_classifiers())
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed_ex1

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

    predictions = []
    for clf in mcb_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = mcb_test.estimate_competence(
        query,
        neighbors,
        distances=distances,
        predictions=np.atleast_2d(predictions))
    assert np.isclose(competences, expected).all()
示例#3
0
def test_estimate_competence_batch(example_estimate_competence):
    _, _, neighbors, distances, dsel_processed, _ = example_estimate_competence

    expected = np.array([[0.57142857, 0.71428571, 0.71428571],
                         [0.71428571, 0.85714286, 0.71428571],
                         [0.57142857, 0.71428571, 0.57142857]])
    mcb_test = MCB()
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed

    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_DSEL_ = bks_dsel_ex3

    predictions = np.array([0, 1, 0])

    competences = mcb_test.estimate_competence(neighbors,
                                               distances=distances,
                                               predictions=np.tile(
                                                   predictions, (3, 1)))
    assert np.isclose(competences, expected).all()
示例#4
0
def test_estimate_competence_batch():
    query = np.ones((3, 2))
    expected = np.array([[0.57142857, 0.71428571, 0.71428571],
                         [0.71428571, 0.85714286, 0.71428571],
                         [0.57142857, 0.71428571, 0.57142857]])
    mcb_test = MCB(create_pool_classifiers())
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed_ex1

    neighbors = neighbors_ex1
    distances = distances_ex1

    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_DSEL_ = bks_dsel_ex3

    predictions = []
    for clf in mcb_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = mcb_test.estimate_competence(query,
                                               neighbors,
                                               distances=distances,
                                               predictions=np.tile(
                                                   predictions, (3, 1)))
    assert np.isclose(competences, expected).all()