Ejemplo n.º 1
0
def test_estimate_competence_woods(index, expected):
    lca_test = LCA(create_pool_classifiers())
    lca_test.processed_dsel = dsel_processed_ex1
    lca_test.neighbors = neighbors_ex1[index, :]
    lca_test.distances = distances_ex1[index, :]
    lca_test.DFP_mask = [1, 1, 1]
    lca_test.DSEL_target = y_dsel_ex1
    query = np.array([1, 1])
    competences = lca_test.estimate_competence(query.reshape(1, -1))
    assert np.isclose(competences, expected).all()
Ejemplo n.º 2
0
def test_estimate_competence_diff_target(index):
    query = np.array([1, 1])

    lca = LCA(create_pool_classifiers())

    lca.processed_dsel = dsel_processed_ex1
    lca.DSEL_target = np.ones(15, dtype=int) * 3

    lca.neighbors = neighbors_ex1[index, :]
    lca.distances = distances_ex1[index, :]
    lca.DFP_mask = [1, 1, 1]

    expected = [0.0, 0.0, 0.0]

    competences = lca.estimate_competence(query.reshape(1, -1))
    assert np.isclose(competences, expected).all()
Ejemplo n.º 3
0
def test_estimate_competence_woods(index, expected):
    lca_test = LCA(create_pool_classifiers())
    lca_test.processed_dsel = dsel_processed_ex1
    lca_test.neighbors = neighbors_ex1[index, :]
    lca_test.distances = distances_ex1[index, :]
    lca_test.DFP_mask = [1, 1, 1]
    lca_test.DSEL_target = y_dsel_ex1

    query = np.atleast_2d([1, 1])

    predictions = []
    for clf in lca_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = lca_test.estimate_competence(query, predictions=np.array(predictions))

    assert np.allclose(competences, expected)
Ejemplo n.º 4
0
def test_estimate_competence_diff_target(index):
    lca_test = LCA(create_pool_classifiers())
    lca_test.processed_dsel = dsel_processed_ex1
    lca_test.DSEL_target = np.ones(15, dtype=int) * 3
    lca_test.neighbors = neighbors_ex1[index, :]
    lca_test.distances = distances_ex1[index, :]
    lca_test.DFP_mask = [1, 1, 1]

    query = np.atleast_2d([1, 1])
    expected = [0.0, 0.0, 0.0]

    predictions = []
    for clf in lca_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = lca_test.estimate_competence(query, predictions=np.array(predictions))

    assert np.isclose(competences, expected).all()
Ejemplo n.º 5
0
def test_estimate_competence_batch(example_estimate_competence):
    _, y, neighbors, distances, dsel_processed, _ = example_estimate_competence

    expected = np.array([[0.75000000,  0.66666667,  0.75000000],
                         [0.80000000, 1.00000000, 0.80000000],
                         [1.00000000, 0.60000000, 0.50000000]])
    lca_test = LCA()
    lca_test.DSEL_processed_ = dsel_processed
    lca_test.DSEL_target_ = y

    query = np.ones((3, 2))

    predictions = np.array([[0, 1, 0]])
    competences = lca_test.estimate_competence(neighbors,
                                               distances=distances,
                                               predictions=np.array(
                                                   predictions))

    assert np.isclose(competences, expected).all()
Ejemplo n.º 6
0
def test_estimate_competence_batch():
    expected = np.array([[0.75000000,  0.66666667,  0.75000000],
                         [0.80000000, 1.00000000, 0.80000000],
                         [1.00000000, 0.60000000, 0.50000000]])
    lca_test = LCA(create_pool_classifiers())
    lca_test.processed_dsel = dsel_processed_ex1
    lca_test.neighbors = neighbors_ex1
    lca_test.distances = distances_ex1
    lca_test.DFP_mask = np.ones((3, 3))
    lca_test.DSEL_target = y_dsel_ex1

    query = np.ones((3, 2))

    predictions = []
    for clf in lca_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = lca_test.estimate_competence(query, predictions=np.array(predictions))

    assert np.isclose(competences, expected).all()
Ejemplo n.º 7
0
def test_estimate_competence_diff_target(index, example_estimate_competence,
                                         create_pool_classifiers):
    _, y, neighbors, distances, dsel_processed, _ = example_estimate_competence

    lca_test = LCA(create_pool_classifiers)
    lca_test.DSEL_processed_ = dsel_processed
    lca_test.DSEL_target_ = np.ones(15, dtype=int) * 3

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

    query = np.atleast_2d([1, 1])
    expected = [0.0, 0.0, 0.0]

    predictions = np.array([[0, 1, 0]])
    competences = lca_test.estimate_competence(
        query,
        neighbors,
        distances=distances,
        predictions=np.array(predictions))

    assert np.isclose(competences, expected).all()