Пример #1
0
def test_proba_with_ds_diff_sizes():
    query = np.ones((10, 2))
    predictions = np.ones((5, 3))
    probabilities = np.ones((5, 3, 2))

    des_mi = DESMI()

    with pytest.raises(ValueError):
        des_mi.predict_proba_with_ds(query, predictions, probabilities)
Пример #2
0
def test_proba_with_ds_diff_sizes():
    query = np.ones((10, 2))
    predictions = np.ones((5, 3))
    probabilities = np.ones((5, 3, 2))

    pool_classifiers = create_pool_classifiers()
    des_mi = DESMI(pool_classifiers)

    with pytest.raises(ValueError):
        des_mi.predict_proba_with_ds(query, predictions, probabilities)
Пример #3
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)
    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,
                                                       DFP_mask=DFP_mask)
    assert np.isclose(predicted_proba, expected, atol=0.01).all()
Пример #4
0
def test_predict_proba_with_ds_soft(create_pool_classifiers):
    expected = np.array([0.61, 0.39])
    DFP_mask = np.ones((1, 6))
    predictions = np.array([[0, 1, 0, 0, 1, 0]])
    probabilities = np.array([[[0.5, 0.5], [1, 0], [0.33, 0.67], [0.5, 0.5],
                               [1, 0], [0.33, 0.67]]])
    pool_classifiers = create_pool_classifiers + create_pool_classifiers
    desmi_test = DESMI(pool_classifiers, DFP=True, voting='soft')
    desmi_test.n_classes_ = 2
    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)

    predicted_proba = desmi_test.predict_proba_with_ds(predictions,
                                                       probabilities,
                                                       DFP_mask=DFP_mask)
    assert np.isclose(predicted_proba, expected, atol=0.01).all()