Example #1
0
def test_classify_instance_weighting():
    query = np.atleast_2d([-1, 1])

    pool_classifiers = create_pool_classifiers() + create_pool_classifiers()
    des_test = DES(pool_classifiers, mode='weighting')
    competences = np.array([0.55, 1.0, 0.2, 0.60, 0.75, 0.3])
    des_test.estimate_competence = MagicMock(return_value=competences)

    predictions = []
    for clf in des_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    predicted_label = des_test.classify_instance(query, np.array(predictions))
    assert predicted_label == 1.0
Example #2
0
def test_classify_instance_selection():
    query = np.atleast_2d([-1, 1])
    pool_classifiers = create_pool_classifiers() + create_pool_classifiers()
    des_test = DES(pool_classifiers, mode='selection')
    # competences = [0.55, 1.0, 0.2, 0.65, 0.75, 0.8]
    selected_index = [0, 1, 5]
    des_test.select = MagicMock(return_value=selected_index)

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

    predicted_label = des_test.classify_instance(query, np.array(predictions))
    assert predicted_label == 0.0