Exemplo n.º 1
0
def test_estimate_competence_kuncheva_ex(example_kuncheva):
    a_priori_test = APriori(k=example_kuncheva['k'])
    test_example = example_kuncheva
    a_priori_test.DSEL_processed_ = test_example['dsel_processed']
    a_priori_test.dsel_scores_ = test_example['dsel_scores']
    a_priori_test.DSEL_target_ = test_example['y_independent']
    a_priori_test.n_classes_ = test_example['n_classes']

    neighbors = test_example['neighbors'].reshape(1, -1)
    distances = test_example['distances'].reshape(1, -1)

    competences = a_priori_test.estimate_competence(neighbors, distances)
    assert np.isclose(competences, 0.70, atol=0.01)
Exemplo n.º 2
0
def test_estimate_competence_all_ones(index, expected, example_all_ones):
    X, y, neighbors, distances, dsel_processed, dsel_scores = example_all_ones

    a_priori_test = APriori()

    a_priori_test.DSEL_processed_ = dsel_processed
    a_priori_test.dsel_scores_ = dsel_scores
    a_priori_test.DSEL_target_ = y
    a_priori_test.n_classes_ = 2

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

    competences = a_priori_test.estimate_competence(neighbors, distances)
    assert np.isclose(competences, expected).all()
Exemplo n.º 3
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()
Exemplo n.º 4
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)
Exemplo n.º 5
0
def test_estimate_competence_batch(example_estimate_competence):
    _, y, nn, _, dsel_processed, dsel_scores = example_estimate_competence
    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(k=3)

    a_priori_test.DSEL_processed_ = dsel_processed
    a_priori_test.dsel_scores_ = dsel_scores
    a_priori_test.DSEL_target_ = y
    a_priori_test.n_classes_ = 2

    nn = nn[:, 0:3]
    distances = np.ones((3, 3))

    competences = a_priori_test.estimate_competence(nn,
                                                    distances)
    assert np.allclose(competences, expected, atol=0.01)
Exemplo n.º 6
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)