Ejemplo n.º 1
0
 def __init__(
     self,
     name: str,
     model_params: Dict[str, Any],
     classifier_paths: Iterable[Tuple[str, str]],
 ) -> None:
     super().__init__(name, model_params, classifier_paths)
     self._selector = RRC(self.classifiers, **model_params)
Ejemplo n.º 2
0
def test_source_competence_rrc():
    rrc_test = RRC([create_base_classifier(return_value=1, return_prob=1.0)])
    rrc_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]])
    rrc_test.DSEL_target = [1, 0, 0, 1]
    rrc_test.n_classes = 3
    rrc_test.n_samples = 4
    C_src = rrc_test.source_competence()
    expected = np.array([[0.7849], [0.3328], [0.6428], [0.1194]])
    assert np.allclose(C_src, expected, atol=0.01)
Ejemplo n.º 3
0
def test_source_competence_rrc():
    rrc_test = RRC()
    rrc_test.n_classifiers_ = 1
    rrc_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)
    rrc_test.DSEL_target_ = [1, 0, 0, 1]
    rrc_test.n_classes_ = 3
    rrc_test.n_samples_ = 4
    C_src = rrc_test.source_competence()
    expected = np.array([[0.7849], [0.3328], [0.6428], [0.1194]])
    assert np.allclose(C_src, expected, atol=0.01)
Ejemplo n.º 4
0
def test_source_competence_rrc():
    pool_classifiers = [
        create_base_classifier(return_value=1, return_prob=1.0)
    ]
    rrc_test = RRC(pool_classifiers=pool_classifiers)
    rrc_test.n_classifiers_ = len(pool_classifiers)
    rrc_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 and 3 classes
    rrc_test.DSEL_target_ = [1, 0, 0, 1]
    rrc_test.n_classes_ = 3
    rrc_test.n_samples_ = 4
    C_src = rrc_test.source_competence()
    expected = np.array([[0.7849], [0.3328], [0.6428], [0.1194]])
    assert np.allclose(C_src, expected, atol=0.01)
Ejemplo n.º 5
0
def test_check_estimator_RRC():
    check_estimator(RRC())
Ejemplo n.º 6
0
def test_rrc(knn_methods):
    pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers()

    rrc = RRC(pool_classifiers, knn_classifier=knn_methods)
    rrc.fit(X_dsel, y_dsel)
    assert np.isclose(rrc.score(X_test, y_test), 0.97340425531914898)
Ejemplo n.º 7
0
    model_perceptron = CalibratedClassifierCV(Perceptron(max_iter=100)).fit(
        X_train, y_train)
    model_linear_svm = CalibratedClassifierCV(LinearSVC()).fit(
        X_train, y_train)
    model_svc = SVC(probability=True).fit(X_train, y_train)
    model_bayes = GaussianNB().fit(X_train, y_train)
    model_tree = DecisionTreeClassifier().fit(X_train, y_train)
    model_knn = KNeighborsClassifier(n_neighbors=5).fit(X_train, y_train)
    pool_classifiers = [
        model_perceptron, model_linear_svm, model_svc, model_bayes, model_tree,
        model_knn
    ]

    # Initializing the DS techniques
    knop = KNOP(pool_classifiers)
    rrc = RRC(pool_classifiers)
    lca = LCA(pool_classifiers)
    mcb = MCB(pool_classifiers)
    aposteriori = APosteriori(pool_classifiers)

    # Fitting the techniques
    knop.fit(X_dsel, y_dsel)
    rrc.fit(X_dsel, y_dsel)
    lca.fit(X_dsel, y_dsel)
    mcb.fit(X_dsel, y_dsel)
    aposteriori.fit(X_dsel, y_dsel)

    # Calculate classification accuracy of each technique
    print('Evaluating DS techniques:')
    print('Classification accuracy KNOP: ', knop.score(X_test, y_test))
    print('Classification accuracy RRC: ', rrc.score(X_test, y_test))