Example #1
0
def test_minimum_diff(knn_methods):
    pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers()

    minimum_diff = MinimumDifference(pool_classifiers,
                                     knn_classifier=knn_methods)
    minimum_diff.fit(X_dsel, y_dsel)
    assert np.isclose(minimum_diff.score(X_test, y_test), 0.97340425531914898)
Example #2
0
def test_source_competence_minimum_difference():
    md_test = MinimumDifference()
    md_test.n_classifiers_ = 1
    md_test.dsel_scores_ = np.array([[[0.3, 0.6, 0.1],
                                      [1.0 / 3, 1.0 / 3, 1.0 / 3],
                                      [0.5, 0.2, 0.3],
                                      [0.5, 0.2, 0.3]]]).reshape(4, 1, 3)

    md_test.DSEL_target_ = [1, 0, 0, 1]
    md_test.n_classes_ = 3
    md_test.n_samples_ = 4
    C_src = md_test.source_competence()
    expected = np.array([[0.3], [0.0], [0.2], [-0.3]])
    assert np.allclose(C_src, expected, atol=0.01)
Example #3
0
def test_source_competence_minimum_difference():
    md_test = MinimumDifference(
        [create_base_classifier(return_value=1, return_prob=1.0)])
    md_test.dsel_scores = np.array([[0.3, 0.6,
                                     0.1], [1.0 / 3, 1.0 / 3, 1.0 / 3],
                                    [0.5, 0.2, 0.3], [0.5, 0.2, 0.3]])
    md_test.DSEL_target = [1, 0, 0, 1]
    md_test.n_classes = 3
    md_test.n_samples = 4
    C_src = md_test.source_competence()
    expected = np.array([[0.3], [0.0], [0.2], [-0.3]])
    assert np.allclose(C_src, expected, atol=0.01)
def test_source_competence_minimum_difference():
    pool_classifiers = [
        create_base_classifier(return_value=1, return_prob=1.0)
    ]
    md_test = MinimumDifference(pool_classifiers=pool_classifiers)
    md_test.n_classifiers_ = len(pool_classifiers)
    md_test.dsel_scores_ = np.array(
        [[[0.3, 0.6, 0.1], [1.0 / 3, 1.0 / 3, 1.0 / 3], [0.5, 0.2, 0.3],
          [0.5, 0.2, 0.3]]]).reshape(4, 1,
                                     3)  # 4 samples, 1 classifier, 3 classes

    md_test.DSEL_target_ = [1, 0, 0, 1]
    md_test.n_classes_ = 3
    md_test.n_samples_ = 4
    C_src = md_test.source_competence()
    expected = np.array([[0.3], [0.0], [0.2], [-0.3]])
    assert np.allclose(C_src, expected, atol=0.01)
Example #5
0
def test_check_estimator_MinimumDifference():
    check_estimator(MinimumDifference())