コード例 #1
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)
コード例 #2
0
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)