예제 #1
0
def test_predict_proba_with_ds():
    query = np.array([-1, 1])
    pool_classifiers = create_pool_classifiers() + create_pool_classifiers()
    desmi_test = DESMI(pool_classifiers, DFP=True)
    desmi_test.DFP_mask = np.ones((1, 6))
    selected_indices = np.array([[0, 1, 5]])

    desmi_test.estimate_competence = MagicMock(return_value=np.ones(6))
    desmi_test.select = MagicMock(return_value=selected_indices)

    desmi_test.n_classes = 2
    expected = np.array([0.61, 0.39])

    predictions = []
    probabilities = []
    for clf in desmi_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
        probabilities.append(clf.predict_proba(query)[0])

    query = np.atleast_2d(query)
    predictions = np.atleast_2d(predictions)
    probabilities = np.array(probabilities)
    probabilities = np.expand_dims(probabilities, axis=0)

    predicted_proba = desmi_test.predict_proba_with_ds(query, predictions,
                                                       probabilities)
    assert np.isclose(predicted_proba, expected, atol=0.01).all()
예제 #2
0
def test_classify_with_ds_single_sample():
    query = np.ones(2)

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

    desmi_test = DESMI(pool_classifiers, DFP=True)
    desmi_test.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)
    assert np.allclose(result, 0)