Exemple #1
0
def test_get_dsel_scores():
    ds_test = DS(create_pool_classifiers())
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.dsel_scores = dsel_scores_ex1
    assert np.array_equal(ds_test._get_scores_dsel(0, 0), np.array([1.0, 0.0]))
    assert np.array_equal(ds_test._get_scores_dsel(1, 0), np.array([0.5, 0.5]))
    assert np.array_equal(ds_test._get_scores_dsel(2, 0), np.array([0.8, 0.2]))
Exemple #2
0
def test_predict_proba_all_agree():
    query = np.atleast_2d([1, 1])
    ds_test = DS(create_pool_classifiers())
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.dsel_scores = dsel_scores_ex1
    ds_test._all_classifier_agree = MagicMock(return_value=True)
    proba = ds_test.predict_proba(query)
    assert np.isclose(proba, np.atleast_2d([0.61, 0.39])).all()
Exemple #3
0
def test_predict_proba_all_agree():
    query = np.atleast_2d([1, 1])
    ds_test = DS(create_pool_classifiers())
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.dsel_scores = dsel_scores_ex1
    backup_all_agree = DS._all_classifier_agree
    DS._all_classifier_agree = MagicMock(return_value=np.array([True]))
    proba = ds_test.predict_proba(query)

    DS._all_classifier_agree = backup_all_agree
    assert np.allclose(proba, np.atleast_2d([0.61, 0.39]))
Exemple #4
0
def test_predict_proba_IH_knn(index):
    query = np.atleast_2d([1, 1])
    ds_test = DS(create_pool_classifiers(), with_IH=True, IH_rate=0.5)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.dsel_scores = dsel_scores_ex1

    ds_test.neighbors = neighbors_ex1[index, :]
    ds_test.distances = distances_ex1[index, :]

    ds_test.roc_algorithm.predict_proba = MagicMock(return_value=np.atleast_2d([0.45, 0.55]))
    proba = ds_test.predict_proba(query)
    assert np.isclose(proba, np.atleast_2d([0.45, 0.55])).all()
Exemple #5
0
def test_get_dsel_scores_all_samples():
    ds_test = DS(create_pool_classifiers())
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.dsel_scores = dsel_scores_ex1
    expected = np.ones((15, 2)) * 0.5
    assert np.array_equal(ds_test._get_scores_dsel(1), expected)