def test_estimate_competence_batch(example_estimate_competence,
                                   create_pool_classifiers):
    X, y, neighbors, distances, _, _ = example_estimate_competence
    query = np.ones((3, 2))
    expected = np.array([[4.0, 3.0, 4.0], [5.0, 2.0, 5.0], [2.0, 5.0, 2.0]])

    knop_test = KNOP(create_pool_classifiers)
    knop_test.fit(X, y)
    knop_test.neighbors = neighbors
    knop_test.distances = distances

    knop_test._get_similar_out_profiles = Mock(return_value=(None, neighbors))
    probabilities = np.zeros((3, 6))

    competences = knop_test.estimate_competence_from_proba(
        query, probabilities)
    assert np.allclose(competences, expected, atol=0.01)
Beispiel #2
0
def test_estimate_competence_batch():
    query = np.ones((3, 2))
    expected = np.array([[4.0, 3.0, 4.0], [5.0, 2.0, 5.0], [2.0, 5.0, 2.0]])

    knop_test = KNOP(create_pool_classifiers())
    knop_test.fit(X_dsel_ex1, y_dsel_ex1)

    knop_test.DFP_mask = np.ones(knop_test.n_classifiers_)
    knop_test.neighbors = neighbors_ex1
    knop_test._get_similar_out_profiles = Mock(return_value=(None,
                                                             neighbors_ex1))
    knop_test.distances = distances_ex1

    probabilities = np.zeros((3, 6))  # not used in this test

    competences = knop_test.estimate_competence_from_proba(
        query, probabilities)
    assert np.allclose(competences, expected, atol=0.01)
Beispiel #3
0
def test_estimate_competence(index, expected):
    query = np.atleast_2d([1, 1])

    knop_test = KNOP(create_pool_classifiers())
    knop_test.fit(X_dsel_ex1, y_dsel_ex1)

    knop_test.DFP_mask = np.ones(knop_test.n_classifiers_)
    knop_test.neighbors = neighbors_ex1[index, :]
    knop_test._get_similar_out_profiles = Mock(
        return_value=(None, np.atleast_2d(neighbors_ex1[index, :])))
    knop_test.distances = distances_ex1[index, :]

    probabilities = []
    for clf in knop_test.pool_classifiers:
        probabilities.append(clf.predict_proba(query))

    probabilities = np.array(probabilities).transpose((1, 0, 2))

    competences = knop_test.estimate_competence_from_proba(
        query, probabilities)
    assert np.allclose(competences, expected, atol=0.01)