示例#1
0
def test_mcb_proba():
    pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers()
    rng = np.random.RandomState(123456)

    mcb = MCB(pool_classifiers, rng=rng, DFP=True)
    mcb.fit(X_dsel, y_dsel)
    probas = mcb.predict_proba(X_test)
    expected = np.load('deslib/tests/expected_values/mcb_proba_DFP.npy')
    assert np.allclose(probas, expected)
示例#2
0
def test_mcb_proba(knn_methods):
    pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers()
    rng = np.random.RandomState(123456)

    mcb = MCB(pool_classifiers, random_state=rng, knn_classifier=knn_methods)

    mcb.fit(X_dsel, y_dsel)
    probas = mcb.predict_proba(X_test)
    expected = np.load(
        'deslib/tests/expected_values/mcb_proba_integration.npy')
    assert np.allclose(probas, expected)
示例#3
0
def test_mcb():
    pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers()
    rng = np.random.RandomState(123456)

    mcb = MCB(pool_classifiers,
              random_state=rng,
              DFP=True,
              with_IH=True,
              IH_rate=0.1)
    mcb.fit(X_dsel, y_dsel)
    assert np.isclose(mcb.score(X_test, y_test), 0.9)
示例#4
0
def test_estimate_competence(index, expected):
    query = np.array([1, 1])

    mcb_test = MCB(create_pool_classifiers())
    mcb_test.processed_dsel = dsel_processed_ex1
    mcb_test.neighbors = neighbors_ex1[index, :]
    mcb_test.distances = distances_ex1[index, :]
    mcb_test.DFP_mask = [1, 1, 1]
    mcb_test.BKS_dsel = bks_dsel_ex1
    competences = mcb_test.estimate_competence(query.reshape(1, -1))
    assert np.isclose(competences, expected).all()
示例#5
0
    def train(train_index, test_index):
        X_train, X_test = X[train_index], X[test_index]
        y_train, y_test = Y[train_index], Y[test_index]

        #train_perc = 0.7
        #split_point = int(train_perc*len(train_index))
        # valid_index = train_index[split_point:]
        # train_index = train_index[:split_point]
        # X_train, X_valid, X_test = X[train_index], X[valid_index], X[test_index]
        # y_train, y_valid, y_test = Y[train_index], Y[valid_index], Y[test_index]
        #print("TRAIN:", train_index, "VALID:", valid_index, "TEST:", test_index)

        X_train, X_valid, y_train, y_valid = train_test_split(
            X_train, y_train, test_size=0.3, random_state=seed)
        pool_classifiers.fit(X_train, y_train)

        validation_data, validation_labels = get_validation_data(
            X_valid, y_valid, 0.5, hardness=hardness)

        dynamic_selection_algorithm = None
        try:
            if args.dynamic_selection == True and args.dynamic_algorithm is None:
                raise ValueError(
                    'Dynamic selection requires you provide an algorithm.')
            elif args.dynamic_selection == True and args.dynamic_algorithm is not None:
                if args.dynamic_algorithm == 'ola':
                    dynamic_selection_algorithm = OLA(pool_classifiers,
                                                      random_state=seed)
                elif args.dynamic_algorithm == 'lca':
                    dynamic_selection_algorithm = LCA(pool_classifiers,
                                                      random_state=seed)
                elif args.dynamic_algorithm == 'mcb':
                    dynamic_selection_algorithm = MCB(pool_classifiers,
                                                      random_state=seed)
                elif args.dynamic_algorithm == 'knorau':
                    dynamic_selection_algorithm = KNORAU(pool_classifiers,
                                                         random_state=seed)
                elif args.dynamic_algorithm == 'kne':
                    dynamic_selection_algorithm = KNORAE(pool_classifiers,
                                                         random_state=seed)

                dynamic_selection_algorithm.fit(validation_data,
                                                validation_labels)
                preds = dynamic_selection_algorithm.predict(X_test)
            else:
                # Static combination by voting
                preds = voting(X_test, pool_classifiers)
        except Exception as error:
            raise error

        acc = get_accuracy_score(y_test, preds)
        g1 = get_g1_score(y_test, preds, average='macro')
        f1 = get_f1_score(y_test, preds)
        roc = roc_auc_score(y_test, preds, average='macro')

        return dict(f1=f1, g1=g1, acc=acc, roc=roc)
示例#6
0
def test_estimate_competence3(index, expected):
    query = np.array([1, 1])

    mcb_test = MCB(create_pool_classifiers())
    mcb_test.processed_dsel = dsel_processed_ex1
    mcb_test.neighbors = neighbors_ex1[index, :]
    mcb_test.distances = distances_ex1[index, :]
    mcb_test.DFP_mask = [1, 1, 1]
    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_dsel = bks_dsel_ex3
    competences = mcb_test.estimate_competence(query.reshape(1, -1))
    assert np.isclose(competences, expected).all()
示例#7
0
def test_estimate_competence(index, expected):
    query = np.atleast_2d([1, 1])

    mcb_test = MCB(create_pool_classifiers())
    mcb_test.processed_dsel = dsel_processed_ex1
    mcb_test.neighbors = neighbors_ex1[index, :]
    mcb_test.distances = distances_ex1[index, :]
    mcb_test.DFP_mask = [1, 1, 1]
    mcb_test.BKS_dsel = bks_dsel_ex1

    predictions = []
    for clf in mcb_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = mcb_test.estimate_competence(query, predictions=np.atleast_2d(predictions))
    assert np.isclose(competences, expected).all()
示例#8
0
def test_estimate_competence_batch():
    query = np.ones((3, 2))
    expected = np.array([[0.57142857,  0.71428571,  0.71428571],
                         [0.71428571, 0.85714286, 0.71428571],
                         [0.57142857, 0.71428571, 0.57142857]])
    mcb_test = MCB(create_pool_classifiers())
    mcb_test.processed_dsel = dsel_processed_ex1
    mcb_test.neighbors = neighbors_ex1
    mcb_test.distances = distances_ex1
    mcb_test.DFP_mask = np.ones((3, 3))
    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_dsel = bks_dsel_ex3

    predictions = []
    for clf in mcb_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = mcb_test.estimate_competence(query, predictions=np.tile(predictions, (3, 1)))
    assert np.isclose(competences, expected).all()
示例#9
0
def test_bks_transform():
    query = np.array([0, -1])

    pool_classifiers = create_pool_classifiers()
    mcb_test = MCB(pool_classifiers)
    value = mcb_test._BKS_transform(query.reshape(1, -1))
    expected = np.array([0, 1, 0])
    assert np.equal(value, expected).all()

    pool_classifiers2 = create_pool_all_agree(1, 10)
    mcb_test2 = MCB(pool_classifiers2)
    bks_result = mcb_test2._BKS_transform(query)
    expected = np.array([1] * 10)
    assert np.equal(bks_result, expected).all()
示例#10
0
def test_estimate_competence2(index, expected, example_estimate_competence):

    _, _, neighbors, distances, dsel_processed, _ = example_estimate_competence

    mcb_test = MCB()
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed

    neighbors = neighbors[index, :].reshape(1, -1)
    distances = distances[index, :].reshape(1, -1)
    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_DSEL_ = bks_dsel_ex2

    predictions = np.array([[0, 1, 0]])

    competences = mcb_test.estimate_competence(
        neighbors, distances=distances, predictions=np.atleast_2d(predictions))
    assert np.isclose(competences, expected).all()
示例#11
0
def test_estimate_competence(index, expected):
    query = np.atleast_2d([1, 1])

    mcb_test = MCB(create_pool_classifiers())
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed_ex1

    neighbors = neighbors_ex1[index, :].reshape(1, -1)
    distances = distances_ex1[index, :].reshape(1, -1)
    mcb_test.BKS_DSEL_ = bks_dsel_ex1

    predictions = []
    for clf in mcb_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])
    competences = mcb_test.estimate_competence(
        query,
        neighbors,
        distances=distances,
        predictions=np.atleast_2d(predictions))
    assert np.isclose(competences, expected).all()
示例#12
0
def test_estimate_competence_batch(example_estimate_competence):
    _, _, neighbors, distances, dsel_processed, _ = example_estimate_competence

    expected = np.array([[0.57142857, 0.71428571, 0.71428571],
                         [0.71428571, 0.85714286, 0.71428571],
                         [0.57142857, 0.71428571, 0.57142857]])
    mcb_test = MCB()
    mcb_test.n_classifiers_ = 3
    mcb_test.DSEL_processed_ = dsel_processed

    # Only changing the pre-processed BKS to see if the filter works.
    mcb_test.BKS_DSEL_ = bks_dsel_ex3

    predictions = np.array([0, 1, 0])

    competences = mcb_test.estimate_competence(neighbors,
                                               distances=distances,
                                               predictions=np.tile(
                                                   predictions, (3, 1)))
    assert np.isclose(competences, expected).all()
示例#13
0
def test_similarity_threshold_type(similarity_threshold):

    with pytest.raises(TypeError):
        mcb = MCB(create_pool_classifiers(),
                  similarity_threshold=similarity_threshold)
        mcb.fit(X_dsel_ex1, y_dsel_ex1)
示例#14
0
def test_predict_proba():
    X = X_dsel_ex1
    y = y_dsel_ex1
    clf1 = Perceptron()
    clf1.fit(X, y)
    MCB([clf1, clf1]).fit(X, y)
示例#15
0
    RF = RandomForestClassifier()
    RF.fit(X_train, y_train)

    X_train, X_dsel, y_train, y_dsel = train_test_split(X, y, test_size=0.50)

    # Training a random forest to be used as the pool of classifiers. We set the maximum depth of the tree so that it
    # can estimate probabilities
    pool_classifiers = RandomForestClassifier(n_estimators=10, max_depth=5)
    pool_classifiers.fit(X_train, y_train)

    # Initialize a DS technique. Here we specify the size of the region of competence (5 neighbors)
    knorau = KNORAU(pool_classifiers)
    kne = KNORAE(pool_classifiers, k=5)
    desp = DESP(pool_classifiers, k=5)
    ola = OLA(pool_classifiers, k=5)
    mcb = MCB(pool_classifiers, k=5)
    meta = METADES(pool_classifiers, k=5)

    # Fit the DS techniques
    knorau.fit(X_dsel, y_dsel)
    kne.fit(X_dsel, y_dsel)
    desp.fit(X_dsel, y_dsel)
    meta.fit(X_dsel, y_dsel)
    ola.fit(X_dsel, y_dsel)
    mcb.fit(X_dsel, y_dsel)

    # Calculate classification accuracy of each technique
    print('Classification accuracy RF: ', RF.score(X_test, y_test))
    print('Evaluating DS techniques:')
    print('Classification accuracy KNORAU: ', knorau.score(X_test, y_test))
    print('Classification accuracy KNORA-Eliminate: ',
示例#16
0
    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))
    print('Classification accuracy LCA: ', lca.score(X_test, y_test))
    print('Classification accuracy A posteriori: ',
示例#17
0
def test_similarity_threshold_type(similarity_threshold):

    with pytest.raises(TypeError):
        MCB(create_pool_classifiers(),
            similarity_threshold=similarity_threshold)
示例#18
0
def main():
    ###############################################################################
    # Preparing the dataset
    # ---------------------
    # In this part we load the breast cancer dataset from scikit-learn and
    # preprocess it in order to pass to the DS models. An important point here is
    # to normalize the data so that it has zero mean and unit variance, which is
    # a common requirement for many machine learning algorithms.
    # This step can be easily done using the StandardScaler class.

    rng = np.random.RandomState(123)
    data = load_breast_cancer()
    X = data.data
    y = data.target
    # split the data into training and test data
    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        test_size=0.33,
                                                        random_state=rng)

    # Scale the variables to have 0 mean and unit variance
    scaler = StandardScaler()
    X_train = scaler.fit_transform(X_train)
    X_test = scaler.transform(X_test)

    # Split the data into training and DSEL for DS techniques
    X_train, X_dsel, y_train, y_dsel = train_test_split(X_train,
                                                        y_train,
                                                        test_size=0.5,
                                                        random_state=rng)

    # Train a pool of 100 base classifiers
    pool_classifiers = BaggingClassifier(Perceptron(max_iter=10),
                                         n_estimators=100,
                                         random_state=rng)
    pool_classifiers.fit(X_train, y_train)

    # Initialize the DS techniques
    knorau = KNORAU(pool_classifiers)
    kne = KNORAE(pool_classifiers)
    desp = DESP(pool_classifiers)
    ola = OLA(pool_classifiers)
    mcb = MCB(pool_classifiers)

    ###############################################################################
    # Calibrating base classifiers
    # -----------------------------
    # Some dynamic selection techniques requires that the base classifiers estimate
    # probabilities in order to estimate its competence level. Since the Perceptron
    # model is not a probabilistic classifier (does not implements the
    # predict_proba method, it needs to be calibrated for
    # probability estimation before being used by such DS techniques. This step can
    # be conducted using the CalibrateClassifierCV class from scikit-learn. Note
    # that in this example we pass a prefited pool of classifiers to the
    # calibration method in order to use exactly the same pool used in the other
    # DS methods.
    calibrated_pool = []
    for clf in pool_classifiers:
        calibrated = CalibratedClassifierCV(base_estimator=clf, cv='prefit')
        calibrated.fit(X_dsel, y_dsel)
        calibrated_pool.append(calibrated)

    apriori = APriori(calibrated_pool)
    meta = METADES(calibrated_pool)

    knorau.fit(X_dsel, y_dsel)
    kne.fit(X_dsel, y_dsel)
    desp.fit(X_dsel, y_dsel)
    ola.fit(X_dsel, y_dsel)
    mcb.fit(X_dsel, y_dsel)
    apriori.fit(X_dsel, y_dsel)
    meta.fit(X_dsel, y_dsel)

    ###############################################################################
    # Evaluating the methods
    # -----------------------
    # Let's now evaluate the methods on the test set. We also use the performance
    # of Bagging (pool of classifiers without any selection) as a baseline
    # comparison. We can see that  the majority of DS methods achieve higher
    # classification accuracy.

    print('Evaluating DS techniques:')
    print('Classification accuracy KNORA-Union: ',
          knorau.score(X_test, y_test))
    print('Classification accuracy KNORA-Eliminate: ',
          kne.score(X_test, y_test))
    print('Classification accuracy DESP: ', desp.score(X_test, y_test))
    print('Classification accuracy OLA: ', ola.score(X_test, y_test))
    print('Classification accuracy A priori: ', apriori.score(X_test, y_test))
    print('Classification accuracy MCB: ', mcb.score(X_test, y_test))
    print('Classification accuracy META-DES: ', meta.score(X_test, y_test))
    print('Classification accuracy Bagging: ',
          pool_classifiers.score(X_test, y_test))
示例#19
0
def test_check_estimator():
    check_estimator(MCB())
示例#20
0
def test_similarity_threshold_type(similarity_threshold, create_X_y):
    X, y = create_X_y
    with pytest.raises(TypeError):
        mcb = MCB(similarity_threshold=similarity_threshold)
        mcb.fit(X, y)
示例#21
0
                                                    y_train,
                                                    test_size=0.5,
                                                    random_state=rng)

# Train a pool of 100 base classifiers
pool_classifiers = BaggingClassifier(Perceptron(max_iter=10),
                                     n_estimators=100,
                                     random_state=rng)
pool_classifiers.fit(X_train, y_train)

# Initialize the DS techniques
knorau = KNORAU(pool_classifiers)
kne = KNORAE(pool_classifiers)
desp = DESP(pool_classifiers)
ola = OLA(pool_classifiers)
mcb = MCB(pool_classifiers, random_state=rng)

###############################################################################
# Calibrating base classifiers
# -----------------------------
# Some dynamic selection techniques requires that the base classifiers estimate
# probabilities in order to estimate its competence level. Since the Perceptron
# model is not a probabilistic classifier (does not implements the
# predict_proba method, it needs to be calibrated for
# probability estimation before being used by such DS techniques. This step can
# be conducted using the CalibrateClassifierCV class from scikit-learn. Note
# that in this example we pass a prefited pool of classifiers to the
# calibration method in order to use exactly the same pool used in the other
# DS methods.
calibrated_pool = []
for clf in pool_classifiers:
示例#22
0
def test_predict_proba(create_X_y):
    X, y = create_X_y

    clf1 = Perceptron()
    clf1.fit(X, y)
    MCB([clf1, clf1]).fit(X, y)
示例#23
0
    def _generate_local_pool(self, query):
        """
        Local pool generation. 
        
        This procedure populates the "pool_classifiers" based on the query sample's neighborhood.
        Thus, for each query sample, a different pool is created.

        In each iteration, the training samples near the query sample are singled out and a 
        subpool is generated using the Self-Generating Hyperplanes (SGH) method. 
        Then, the DCS technique selects the best classifier in the generated subpool and it is added to the local pool. 
        In the following iteration, the neighborhood is increased and another SGH-generated subpool is obtained 
        over the new neighborhood, and again the DCS technique singles out the best in it, which is then added to the local pool. 
        This process is repeated until the pool reaches "n_classifiers".

        Parameters
        ----------
        query : array of shape = [n_features] 
                The test sample.

        Returns
        -------
        self

        References
        ----------

        M. A. Souza, G. D. Cavalcanti, R. M. Cruz, R. Sabourin, On the characterization of the
        oracle for dynamic classi
er selection, in: International Joint Conference on Neural Networks,
        IEEE, 2017, pp. 332-339.
        """
        n_samples, _ = self.DSEL_data.shape

        self.pool_classifiers = []

        n_err = 0
        max_err = 2 * self.n_classifiers

        curr_k = self.k

        # Classifier count
        n = 0

        while n < self.n_classifiers and n_err < max_err:

            subpool = SGH()

            included_samples = np.zeros((n_samples), int)

            if self.knne:
                idx_neighb = np.array([], dtype=int)

                # Obtain neighbors of each class individually
                for j in np.arange(0, self.n_classes):
                    # Obtain neighbors from the classes in the RoC
                    if np.any(self.classes[j] == self.DSEL_target[
                            self.neighbors[0][np.arange(0, curr_k)]]):
                        nc = np.where(self.classes[j] == self.DSEL_target[
                            self.neighbors[0]])
                        idx_nc = self.neighbors[0][nc]
                        idx_nc = idx_nc[np.arange(
                            0, np.minimum(curr_k, len(idx_nc)))]
                        idx_neighb = np.concatenate((idx_neighb, idx_nc),
                                                    axis=0)

            else:
                idx_neighb = np.asarray(self.neighbors)[0][np.arange(
                    0, curr_k)]

            # Indicate participating instances in the training of the subpool
            included_samples[idx_neighb] = 1

            curr_classes = np.unique(self.DSEL_target[idx_neighb])

            # If there are +1 classes in the local region
            if len(curr_classes) > 1:
                # Obtain SGH pool
                subpool.fit(self.DSEL_data, self.DSEL_target, included_samples)

                # Adjust chosen DCS technique parameters
                if self.ds_tech == 'ola':
                    ds = OLA(subpool, k=len(idx_neighb))  # change for self.k
                elif self.ds_tech == 'lca':
                    ds = LCA(subpool, k=len(idx_neighb))
                elif self.ds_tech == 'mcb':
                    ds = MCB(subpool, k=len(idx_neighb))
                elif self.ds_tech == 'mla':
                    ds = MLA(subpool, k=len(idx_neighb))
                elif self.ds_tech == 'a_priori':
                    ds = APriori(subpool, k=len(idx_neighb))
                elif self.ds_tech == 'a_posteriori':
                    ds = APosteriori(subpool, k=len(idx_neighb))

                # Fit ds technique
                ds.fit(self.DSEL_data, self.DSEL_target)

                neighb = np.in1d(
                    self.neighbors,
                    idx_neighb)  # True/False vector of selected neighbors

                # Set distances and neighbors of the query sample (already calculated)
                ds.distances = np.asarray([self.distances[0][neighb]
                                           ])  # Neighborhood
                ds.neighbors = np.asarray([self.neighbors[0][neighb]
                                           ])  # Neighborhood

                ds.DFP_mask = np.ones(ds.n_classifiers)

                # Estimate competence
                comp = ds.estimate_competence(query, ds._predict_base(query))

                # Select best classifier in subpool
                sel_c = ds.select(comp)

                # Add to local pool
                self.pool_classifiers.append(copy.deepcopy(subpool[sel_c[0]]))

                n += 1
            # else:
            #     # Exception: fewer than 2 classes in the neighborhood
            #     print('OPS! Next!')

            # Increase neighborhood size
            curr_k += 2
            n_err += 1

        return self
示例#24
0
# We set the maximum depth of the tree so that it
# can estimate probabilities
pool_classifiers = RandomForestClassifier(n_estimators=100, max_depth=5,
                                          random_state=rng)
pool_classifiers.fit(X_train, y_train)

stacked = StackedClassifier(pool_classifiers, LogisticRegression())
stacked.fit(X_dsel, y_dsel)

# Initialize a DS technique. Here we specify the size of
# the region of competence (5 neighbors)
knorau = KNORAU(pool_classifiers, random_state=rng)
kne = KNORAE(pool_classifiers, k=5, random_state=rng)
desp = DESP(pool_classifiers, k=5, random_state=rng)
ola = OLA(pool_classifiers, k=5, random_state=rng)
mcb = MCB(pool_classifiers, k=5, random_state=rng)
meta = METADES(pool_classifiers, k=5, random_state=rng)

# Fit the DS techniques
knorau.fit(X_dsel, y_dsel)
kne.fit(X_dsel, y_dsel)
desp.fit(X_dsel, y_dsel)
meta.fit(X_dsel, y_dsel)
ola.fit(X_dsel, y_dsel)
mcb.fit(X_dsel, y_dsel)

###############################################################################
# Plotting the results
# -----------------------
# Let's now evaluate the methods on the test set.
     sm = SMOTE()
     Feature_train_o, Label_train_o = sm.fit_sample(Feature_train, Label_train.ravel())
     bdt = AdaBoostClassifier(DecisionTreeClassifier(max_depth=2, min_samples_split=20, min_samples_leaf=5),
                              algorithm='SAMME', n_estimators=200, learning_rate=0.8)
     bdt.fit(Feature_train_o, Label_train_o)
     Label_predict = bdt.predict(Feature_test)
 elif m == 'META-DES':
     pool_classifiers = RandomForestClassifier(n_estimators=10)
     pool_classifiers.fit(Feature_train, Label_train.ravel())
     metades = METADES(pool_classifiers)
     metades.fit(Feature_train, Label_train.ravel())
     Label_predict = metades.predict(Feature_test)
 elif m == 'MCB':
     pool_classifiers = RandomForestClassifier(n_estimators=10)
     pool_classifiers.fit(Feature_train, Label_train.ravel())
     mcb = MCB(pool_classifiers)
     mcb.fit(Feature_train, Label_train.ravel())
     Label_predict = mcb.predict(Feature_test)
 elif m == 'DES-MI':
     pool_classifiers = RandomForestClassifier(n_estimators=10)
     pool_classifiers.fit(Feature_train, Label_train.ravel())
     dmi = DESMI(pool_classifiers)
     dmi.fit(Feature_train, Label_train.ravel())
     Label_predict = dmi.predict(Feature_test)
 elif m == 'One_vs_Rest-SMOTE-XGBoost':
     sm = SMOTE()
     Feature_train_o, Label_train_o = sm.fit_sample(Feature_train, Label_train.ravel())
     clf = OneVsRestClassifier(xgboost.XGBClassifier())
     clf.fit(Feature_train_o, Label_train_o)
     Label_predict = clf.predict(Feature_test)
 elif m == 'One_vs_Rest-XGBoost':
示例#26
0
X_train, X_dsel, y_train, y_dsel = train_test_split(X_train,
                                                    y_train,
                                                    test_size=0.50,
                                                    random_state=rng)

stacked = StackedClassifier(RF, LogisticRegression())
stacked.fit(X_dsel, y_dsel)

# Initialize a DS technique. Here we specify the size of
# the region of competence (5 neighbors)
knorau = KNORAU(RF, k=5, random_state=rng)
kne = KNORAE(RF, k=5, random_state=rng)
desp = DESP(RF, k=5, random_state=rng)
ola = OLA(RF, k=5, random_state=rng)
mcb = MCB(RF, k=5, random_state=rng)
meta = METADES(RF, k=5, random_state=rng)

# Fit the DS techniques
knorau.fit(X_dsel, y_dsel)
kne.fit(X_dsel, y_dsel)
desp.fit(X_dsel, y_dsel)
meta.fit(X_dsel, y_dsel)
ola.fit(X_dsel, y_dsel)
mcb.fit(X_dsel, y_dsel)

###############################################################################
# Plotting the results
# -----------------------
# Let's now evaluate the methods on the test set.