Ejemplo n.º 1
0
def test_classify_with_ds_diff_sizes():
    query = np.ones((10, 2))
    predictions = np.ones((5, 3))

    des_mi = DESMI()

    with pytest.raises(ValueError):
        des_mi.classify_with_ds(query, predictions)
Ejemplo n.º 2
0
def test_classify_with_ds_single_sample():
    query = np.ones(2)

    # simulated predictions of the pool of classifiers
    predictions = np.array([0, 1, 0])

    desmi_test = DESMI(DFP=True)
    DFP_mask = np.ones((1, 3))
    desmi_test.estimate_competence = MagicMock(return_value=(np.ones((1, 3))))
    desmi_test.select = MagicMock(return_value=np.array([[0, 2]]))
    result = desmi_test.classify_with_ds(query, predictions, DFP_mask=DFP_mask)
    assert np.allclose(result, 0)
Ejemplo n.º 3
0
def test_classify_with_ds_batch_samples():
    n_samples = 10

    # simulated predictions of the pool of classifiers
    predictions = np.tile(np.array([0, 1, 0]), (n_samples, 1))

    desmi_test = DESMI()
    desmi_test.n_classes_ = 2
    desmi_test.estimate_competence = MagicMock(
        return_value=(np.ones((n_samples, 3))))
    desmi_test.select = MagicMock(
        return_value=np.tile(np.array([[0, 2]]), (n_samples, 1)))
    result = desmi_test.classify_with_ds(predictions)
    assert np.allclose(result, np.zeros(10))
Ejemplo n.º 4
0
def test_classify_with_ds_batch_samples():
    n_samples = 10
    # Passing 10 samples for classification automatically
    query = np.ones((n_samples, 2))

    pool_classifiers = create_pool_classifiers()
    # simulated predictions of the pool of classifiers
    predictions = np.tile(np.array([0, 1, 0]), (n_samples, 1))

    desmi_test = DESMI(pool_classifiers)
    desmi_test.estimate_competence = MagicMock(return_value=(np.ones((n_samples, 3))))
    desmi_test.select = MagicMock(return_value=np.tile(np.array([[0, 2]]), (n_samples, 1)))
    result = desmi_test.classify_with_ds(query, predictions)
    assert np.allclose(result, np.zeros(10))