コード例 #1
0
ファイル: test_base.py プロジェクト: trasse/DESlib
def test_label_encoder_only_dsel_allagree():
    X_dsel_ex1 = np.array([[-1, 1], [-0.75, 0.5], [-1.5, 1.5]])
    y_dsel_ex1 = np.array(['cat', 'dog', 'plane'])

    query = np.atleast_2d([[1, 0], [-1, -1]])
    ds_test = BaseDS(create_pool_classifiers_dog(), k=2)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.neighbors = neighbors_ex1[0, :]
    ds_test.distances = distances_ex1[0, :]
    predictions = ds_test.predict(query)
    assert np.array_equal(predictions, ['dog', 'dog'])
コード例 #2
0
ファイル: test_base.py プロジェクト: victorlorena/DESlib
def test_predict_proba_instance_called(index):
    query = np.atleast_2d([1, 1])
    ds_test = BaseDS(create_pool_classifiers(), with_IH=True, IH_rate=0.10)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)

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

    ds_test.predict_proba_with_ds = MagicMock(return_value=np.atleast_2d([0.25, 0.75]))
    proba = ds_test.predict_proba(query)
    assert np.allclose(proba, np.atleast_2d([0.25, 0.75]))
コード例 #3
0
ファイル: test_base.py プロジェクト: victorlorena/DESlib
def test_predict_proba_IH_knn(index):
    query = np.atleast_2d([1, 1])
    ds_test = BaseDS(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.allclose(proba, np.atleast_2d([0.45, 0.55]))
コード例 #4
0
ファイル: test_base.py プロジェクト: victorlorena/DESlib
def test_label_encoder_only_dsel():
    X_dsel_ex1 = np.array([[-1, 1], [-0.75, 0.5], [-1.5, 1.5]])
    y_dsel_ex1 = np.array(['cat', 'dog', 'plane'])

    query = np.atleast_2d([[1, 0], [-1, -1]])
    ds_test = BaseDS(create_pool_classifiers_dog_cat_plane(), k=2)
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    ds_test.neighbors = neighbors_ex1[0, :]
    ds_test.distances = distances_ex1[0, :]
    ds_test.classify_with_ds = Mock()
    ds_test.classify_with_ds.return_value = [1, 0]  # changed here due to batch processing
    predictions = ds_test.predict(query)
    assert np.array_equal(predictions, ['dog', 'cat'])