Beispiel #1
0
def test_estimate_competence_all_ones(index, expected):
    query = np.array([1, 1])

    a_priori_test = APriori(create_pool_classifiers())

    a_priori_test.processed_dsel = dsel_processed_ex1
    a_priori_test.dsel_scores = dsel_scores_all_ones
    a_priori_test.DSEL_target = y_dsel_ex1
    a_priori_test.n_classes = 2

    a_priori_test.neighbors = neighbors_ex1[index, :]
    a_priori_test.distances = distances_all_ones[index, :]
    a_priori_test.DFP_mask = [1, 1, 1]

    competences = a_priori_test.estimate_competence(query.reshape(1, -1))
    assert np.isclose(competences, expected).all()
Beispiel #2
0
def test_estimate_competence_kuncheva_ex():
    query = np.array([1, 1])

    a_priori_test = APriori([create_base_classifier(return_value=1)],
                            k=k_ex_kuncheva)

    a_priori_test.processed_dsel = dsel_processed_kuncheva
    a_priori_test.dsel_scores = dsel_scores_ex_kuncheva
    a_priori_test.DSEL_target = y_dsel_ex_kuncheva_independent
    a_priori_test.n_classes = n_classes_ex_kuncheva

    a_priori_test.neighbors = neighbors_ex_kuncheva
    a_priori_test.distances = distances_ex_kuncheva
    a_priori_test.DFP_mask = [1]

    competences = a_priori_test.estimate_competence(query.reshape(1, -1))
    assert np.isclose(competences, 0.70, atol=0.01)
Beispiel #3
0
def test_estimate_competence_batch():
    query = np.ones((3, 2))
    expected = np.array([[0.333333, 0.50000, 0.40000],
                         [0.666666, 0.50000, 0.60000],
                         [0.000000, 0.50000, 0.20000]])

    # Using 3 neighbors to facilitate the calculations
    a_priori_test = APriori(create_pool_classifiers(), 3)

    a_priori_test.processed_dsel = dsel_processed_ex1
    a_priori_test.dsel_scores = dsel_scores_ex1
    a_priori_test.DSEL_target = y_dsel_ex1
    a_priori_test.n_classes = 2

    a_priori_test.neighbors = neighbors_ex1[:, 0:3]
    a_priori_test.distances = distances_all_ones[:, 0:3]
    a_priori_test.DFP_mask = np.ones((3, 3))

    competences = a_priori_test.estimate_competence(query)
    assert np.allclose(competences, expected, atol=0.01)