コード例 #1
0
def test_fit():
    """Test for fitting the model."""
    X = rnd.randn(10, 2)
    y = np.hstack((-np.ones((5, )), np.ones((5, ))))
    Z = rnd.randn(10, 2) + 1
    clf = TransferComponentClassifier()
    clf.fit(X, y, Z)
    assert clf.is_trained
コード例 #2
0
def main(source, target, model, target_train_ratio, random_state):

    params = {
        'source': source,
        'target': target,
        'target_train_ratio': target_train_ratio,
        'max_features': 5000,
        'random_state': random_state
    }

    params['partition'] = 'tr'
    tr_X, tr_y = get_data(AmazonDatasetCombined(**params))

    params['partition'] = 'te'
    te_X, te_y = get_data(AmazonDatasetCombined(**params))

    tr_y = tr_y.reshape(-1)
    te_y = te_y.reshape(-1)

    if model == 'lr':
        C = 0.2
        clf = LogisticRegression(solver='lbfgs', max_iter=1000, C=C)
        clf.fit(tr_X, tr_y)

    elif model == 'svm':
        C = 0.2
        clf = LinearSVC(C=C)
        clf.fit(tr_X, tr_y)

    elif model == 'kmm':
        clf = ImportanceWeightedClassifier(iwe='kmm')
        clf.fit(tr_X, tr_y, te_X)

    elif model == 'suba-lr':
        clf = SubspaceAlignedClassifier(loss='logistic')
        clf.fit(tr_X, tr_y, te_X)

    elif model == 'suba-hi':
        clf = SubspaceAlignedClassifier(loss='hinge')
        clf.fit(tr_X, tr_y, te_X)

    elif model == 'tca-lr':
        clf = TransferComponentClassifier(loss='logistic')
        clf.fit(tr_X, tr_y, te_X)

    elif model == 'tca-hi':
        clf = TransferComponentClassifier(loss='hinge')
        clf.fit(tr_X, tr_y, te_X)

    else:
        raise Exception('Unknown model called..')

    tr_score = accuracy_score(tr_y, clf.predict(tr_X))
    te_score = accuracy_score(te_y, clf.predict(te_X))

    return tr_score, te_score
コード例 #3
0
def test_predict():
    """Test for making predictions."""
    X = rnd.randn(10, 2)
    y = np.hstack((-np.ones((5, )), np.ones((5, ))))
    Z = rnd.randn(10, 2) + 1
    clf = TransferComponentClassifier()
    clf.fit(X, y, Z)
    u_pred = clf.predict(Z)
    labels = np.unique(y)
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0
コード例 #4
0
def apply_ENSEMBLE(trainX, trainY, testX, testY, window, source_pos, target_pos):
    classifier_SA_DT = SubspaceAlignedClassifier(loss="dtree")
    classifier_SA_LR = SubspaceAlignedClassifier(loss="logistic")
    classifier_SA_NB = SubspaceAlignedClassifier(loss="berno")
    classifier_TCA_DT = TransferComponentClassifier(loss="dtree")
    classifier_TCA_LR = TransferComponentClassifier(loss="logistic")
    classifier_TCA_NB = TransferComponentClassifier(loss="berno")
    classifier_NN_DT = ImportanceWeightedClassifier(iwe='nn', loss="dtree")
    classifier_NN_LR = ImportanceWeightedClassifier(iwe='nn', loss="logistic")
    classifier_NN_NB = ImportanceWeightedClassifier(iwe='nn', loss="berno")
    classifier_KMM_DT = ImportanceWeightedClassifier(iwe='kmm', loss="dtree")
    classifier_KMM_LR = ImportanceWeightedClassifier(iwe='kmm', loss="logistic")
    classifier_KMM_NB = ImportanceWeightedClassifier(iwe='kmm', loss="berno")
    #
    eclf = EnsembleClassifier(clfs=[ 
        #classifier_SA_DT,
        #classifier_SA_LR,
        #classifier_SA_NB,

        #classifier_TCA_DT,
        #classifier_TCA_LR,
        classifier_TCA_NB,

        classifier_NN_DT,
        #classifier_NN_LR,
        #classifier_NN_NB,

        classifier_KMM_DT,
        classifier_KMM_LR,
        #classifier_KMM_NB
         ])
    eclf.fit(trainX, trainY, testX)
    pred = eclf.predict(testX)
    acc_ENSEMBLE, acc_ENSEMBLE_INFO = check_accuracy(testY, pred)
    #
    return pd.DataFrame(
        [{ 
        'window': window,
        'source_position': source_pos,
        'target_position': target_pos,

        'acc_ENSEMBLE': acc_ENSEMBLE,  
        'acc_ENSEMBLE_INFO': acc_ENSEMBLE_INFO,                                            
        }]
    )
コード例 #5
0
acc_LR_SA = checkAccuracy(testY, pred_naive)
print("acc_LR_SA:", acc_LR_SA)

#i = 0
#for pred_label in pred_LR:
#    print(pred_label, np.max(prob[i]))
#    i+=1

#.predict(testX)
#acc_LR_SA = checkAccuracy(testY, pred)
#print("ACC:", acc_LR_SA);
#
classifier_SA_DT = SubspaceAlignedClassifier(loss="dtree")
classifier_SA_LR = SubspaceAlignedClassifier(loss="logistic")
classifier_SA_NB = SubspaceAlignedClassifier(loss="berno")
classifier_TCA_DT = TransferComponentClassifier(loss="dtree")
classifier_TCA_LR = TransferComponentClassifier(loss="logistic")
classifier_TCA_NB = TransferComponentClassifier(loss="berno")
classifier_NN_DT = ImportanceWeightedClassifier(iwe='nn', loss="dtree")
classifier_NN_LR = ImportanceWeightedClassifier(iwe='nn', loss="logistic")
classifier_NN_NB = ImportanceWeightedClassifier(iwe='nn', loss="berno")
classifier_KMM_DT = ImportanceWeightedClassifier(iwe='kmm', loss="dtree")
classifier_KMM_LR = ImportanceWeightedClassifier(iwe='kmm', loss="logistic")
classifier_KMM_NB = ImportanceWeightedClassifier(iwe='kmm', loss="berno")
#
eclf = EnsembleClassifier(clfs=[
    classifier_SA_DT, classifier_SA_LR, classifier_SA_NB, classifier_TCA_LR,
    classifier_TCA_DT, classifier_TCA_NB, classifier_NN_DT, classifier_NN_LR,
    classifier_NN_NB, classifier_KMM_DT, classifier_KMM_LR, classifier_KMM_NB
],
                          weights=[1, 1])
コード例 #6
0
"""Classifiers"""

# Train a naive logistic regressor
lr = LogisticRegression().fit(X, y)

# Make predictions
pred_naive = lr.predict(Z)

# Select adaptive classifier
if classifier == 'iw':
    # Call an importance-weighted classifier
    clf = ImportanceWeightedClassifier(iwe='lr', loss='logistic')

elif classifier == 'tca':
    # Classifier based on transfer component analysis
    clf = TransferComponentClassifier(loss='logistic', mu=1.)

elif classifier == 'suba':
    # Classifier based on subspace alignment
    clf = SubspaceAlignedClassifier(loss='logistic')

elif classifier == 'scl':
    # Classifier based on subspace alignment
    clf = StructuralCorrespondenceClassifier(num_pivots=2, num_components=1)

elif classifier == 'rba':
    # Robust bias-aware classifier
    clf = RobustBiasAwareClassifier(l2=0.1, max_iter=1000)

elif classifier == 'flda':
    # Feature-level domain-adaptive classifier
    new_ensemble_model = Model(inputs=ensemble_CNN_model.input,
                               outputs=ensemble_CNN_model.layers[-3].output)

    new_x_train = new_ensemble_model.predict(x_train)
    new_x_test = new_ensemble_model.predict(x_test)

    index = random.sample(range(560), 560)
    new_train_data = new_x_train[index]
    new_train_label = np.squeeze(y_train)[index]
    new_test_data = new_x_test

    TCA_classifier = TransferComponentClassifier(
        loss='logistic',
        l2=0.9,
        mu=mu_value,
        num_components=num_components_value,
        kernel_type='rbf',
        bandwidth=bandwidth_value,
        order=2.0,
    )
    TCA_classifier.fit(new_train_data, new_train_label, new_test_data)
    y_pred = TCA_classifier.predict(new_test_data)

    merge_predict_label = merge_result(y_pred)

    print("the predict label of the" + str(i) + "-th subject are:")
    print(merge_predict_label + 1)

    print(
        "____________________________________END_____________________________________________"
    )
コード例 #8
0
def apply_TCA(trainX, trainY, testX, testY, window, source_pos, target_pos):
    ####################################################
    ### Transfer Component Analysis (Pan et al, 2009) 
    ###
    # Decision Tree
    print("\n Transfer Component Analysis (Pan et al, 2009)")
    classifier = TransferComponentClassifier(loss="dtree", num_components=1)
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_DT_TCA, acc_DT_TCA_INFO = check_accuracy(testY, pred_naive)

    # Logistic Regression
    classifier = TransferComponentClassifier(loss="logistic", num_components=100)
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_LR_TCA, acc_LR_TCA_INFO = check_accuracy(testY, pred_naive)

    # Naive Bayes Bernoulli
    classifier = TransferComponentClassifier(loss="berno", num_components=1, l2=100, bandwidth=10, order=100.0, mu=100.0)
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_NB_TCA, acc_NB_TCA_INFO = check_accuracy(testY, pred_naive)

    return pd.DataFrame(
            [{ 
            'window': window,
            'source_position': source_pos,
            'target_position': target_pos,

            'acc_LR_TCA': acc_LR_TCA,
            'acc_LR_TCA_INFO': str(acc_LR_TCA_INFO),                                              
            'acc_DT_TCA': acc_DT_TCA,
            'acc_DT_TCA_INFO': str(acc_DT_TCA_INFO),                                                                            
            'acc_NB_TCA': acc_NB_TCA,
            'acc_NB_TCA_INFO': str(acc_NB_TCA_INFO),                                                
            }]
        )
コード例 #9
0
ファイル: main.py プロジェクト: myhrbeu/py-har
def build_models(trainX, trainY, testX, testY, source_pos, target_pos, window):
    #######################
    ### SEMI-SUPERVISED ###
    ########################
    # Label Propagation
    label_prop_model = LabelPropagation(kernel='knn')
    label_prop_model.fit(trainX, trainY)
    Y_Pred = label_prop_model.predict(testX)
    acc_ss_propagation, acc_ss_propagation_INFO = checkAccuracy(testY, Y_Pred)
    # Label Spreading
    label_prop_models_spr = LabelSpreading(kernel='knn')
    label_prop_models_spr.fit(trainX, trainY)
    Y_Pred = label_prop_models_spr.predict(testX)
    acc_ss_spreading, acc_ss_spreading_INFO = checkAccuracy(testY, Y_Pred)
    ########################
    #### WITHOUT TL ########
    ########################
    # LogisticRegression
    modelLR = LogisticRegression()
    modelLR.fit(trainX, trainY)
    predLR = modelLR.predict(testX)
    accLR, acc_LR_INFO = checkAccuracy(testY, predLR)
    # DecisionTreeClassifier
    modelDT = tree.DecisionTreeClassifier()
    modelDT.fit(trainX, trainY)
    predDT = modelDT.predict(testX)
    accDT, acc_DT_INFO = checkAccuracy(testY, predDT)
    # BernoulliNB
    modelNB = BernoulliNB()
    modelNB.fit(trainX, trainY)
    predND = modelNB.predict(testX)
    accNB, acc_NB_INFO = checkAccuracy(testY, predND)
    #
    print("WITHOUT TL ACC_LR:", accLR, " ACC_DT:", accDT, " ACC_NB:", accNB)
    ########################
    #### WITH TL ########
    ########################

    ####################################################
    ### Kernel Mean Matching (Huang et al., 2006)
    ###
    # Decision Tree
    print("\n Kernel Mean Matching (Huang et al., 2006) ")
    classifier = ImportanceWeightedClassifier(iwe='kmm', loss="dtree")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_DT_KMM, acc_DT_KMM_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_DT_KMM)
    # Logistic Regression
    classifier = ImportanceWeightedClassifier(iwe='kmm', loss="logistic")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_LR_KMM, acc_LR_KMM_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_LR_KMM)
    # Naive Bayes Bernoulli
    classifier = ImportanceWeightedClassifier(iwe='kmm', loss="berno")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_NB_KMM, acc_NB_KMM_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_NB_KMM)
    ####################################################
    ### Nearest-neighbour-based weighting (Loog, 2015)
    ###
    # Decision Tree
    print("\n Nearest-neighbour-based weighting (Loog, 2015)    ")
    classifier = ImportanceWeightedClassifier(iwe='nn', loss="dtree")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_DT_NN, acc_DT_NN_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_DT_NN)
    # Logistic Regression
    print("\n Nearest-neighbour-based weighting (Loog, 2015)    ")
    classifier = ImportanceWeightedClassifier(iwe='nn', loss="logistic")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_LR_NN, acc_LR_NN_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_LR_NN)
    # Naive Bayes Bernoulli
    print("\n Nearest-neighbour-based weighting (Loog, 2015)    ")
    classifier = ImportanceWeightedClassifier(iwe='nn', loss="berno")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_NB_NN, acc_NB_NN_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_NB_NN)

    ####################################################
    ### Transfer Component Analysis (Pan et al, 2009)
    ###
    # Decision Tree
    print("\n Transfer Component Analysis (Pan et al, 2009)")
    classifier = TransferComponentClassifier(loss="dtree", num_components=6)
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_DT_TCA, acc_DT_TCA_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_DT_TCA)
    # Logistic Regression
    classifier = TransferComponentClassifier(loss="logistic", num_components=6)
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_LR_TCA, acc_LR_TCA_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_LR_TCA)
    # Naive Bayes Bernoulli
    classifier = TransferComponentClassifier(loss="berno", num_components=6)
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_NB_TCA, acc_NB_TCA_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_NB_TCA)

    ####################################################
    ### Subspace Alignment (Fernando et al., 2013)
    ###
    # Decision Tree
    print("\n Subspace Alignment (Fernando et al., 2013) ")
    classifier = SubspaceAlignedClassifier(loss="dtree")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_DT_SA, acc_DT_SA_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_DT_SA)
    # Logistic Regression
    print("\n Subspace Alignment (Fernando et al., 2013) ")
    classifier = SubspaceAlignedClassifier(loss="logistic")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_LR_SA, acc_LR_SA_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_LR_SA)
    # Naive Bayes Bernoulli
    print("\n Subspace Alignment (Fernando et al., 2013) ")
    classifier = SubspaceAlignedClassifier(loss="berno")
    classifier.fit(trainX, trainY, testX)
    pred_naive = classifier.predict(testX)
    acc_NB_SA, acc_NB_SA_INFO = checkAccuracy(testY, pred_naive)
    print("ACC:", acc_NB_SA)
    #################################
    ############# ENSEMBLE ##########
    #################################
    classifier_SA_DT = SubspaceAlignedClassifier(loss="dtree")
    classifier_SA_LR = SubspaceAlignedClassifier(loss="logistic")
    classifier_SA_NB = SubspaceAlignedClassifier(loss="berno")
    classifier_TCA_DT = TransferComponentClassifier(loss="dtree")
    classifier_TCA_LR = TransferComponentClassifier(loss="logistic")
    classifier_TCA_NB = TransferComponentClassifier(loss="berno")
    classifier_NN_DT = ImportanceWeightedClassifier(iwe='nn', loss="dtree")
    classifier_NN_LR = ImportanceWeightedClassifier(iwe='nn', loss="logistic")
    classifier_NN_NB = ImportanceWeightedClassifier(iwe='nn', loss="berno")
    classifier_KMM_DT = ImportanceWeightedClassifier(iwe='kmm', loss="dtree")
    classifier_KMM_LR = ImportanceWeightedClassifier(iwe='kmm',
                                                     loss="logistic")
    classifier_KMM_NB = ImportanceWeightedClassifier(iwe='kmm', loss="berno")
    #
    eclf = EnsembleClassifier(
        clfs=[classifier_TCA_DT, classifier_NN_DT, classifier_KMM_DT])
    eclf.fit(trainX, trainY, testX)
    pred = eclf.predict_v2(testX)
    acc_ENSEMBLE, acc_ENSEMBLE_INFO = checkAccuracy(testY, pred)

    ########################
    #### RETURN ########
    ########################
    return pd.DataFrame([{
        'window': window,
        'source_position': source_pos,
        'target_position': target_pos,
        'acc_SS_propagation': acc_ss_propagation,
        'acc_SS_propagation_INFO': acc_ss_propagation_INFO,
        'acc_SS_spreading': acc_ss_spreading,
        'acc_SS_spreading_INFO': acc_ss_spreading_INFO,
        'acc_ENSEMBLE': acc_ENSEMBLE,
        'acc_LR': accLR,
        'acc_LR_INFO': str(acc_LR_INFO),
        'acc_DT': accDT,
        'acc_DT_INFO': str(acc_DT_INFO),
        'acc_NB': accNB,
        'acc_NB_INFO': str(acc_NB_INFO),
        'acc_LR_KMM': acc_LR_KMM,
        'acc_LR_KMM_INFO': str(acc_LR_KMM_INFO),
        'acc_LR_NN': acc_LR_NN,
        'acc_LR_NN_INFO': str(acc_LR_NN_INFO),
        'acc_LR_TCA': acc_LR_TCA,
        'acc_LR_TCA_INFO': str(acc_LR_TCA_INFO),
        'acc_LR_SA': acc_LR_SA,
        'acc_LR_SA_INFO': str(acc_LR_SA_INFO),
        'acc_DT_KMM': acc_DT_KMM,
        'acc_DT_KMM_INFO': str(acc_DT_KMM_INFO),
        'acc_DT_NN': acc_DT_NN,
        'acc_DT_NN_INFO': str(acc_DT_NN_INFO),
        'acc_DT_TCA': acc_DT_TCA,
        'acc_DT_TCA_INFO': str(acc_DT_TCA_INFO),
        'acc_DT_SA': acc_DT_SA,
        'acc_DT_SA_INFO': str(acc_DT_SA_INFO),
        'acc_NB_KMM': acc_NB_KMM,
        'acc_NB_KMM_INFO': str(acc_NB_KMM_INFO),
        'acc_NB_NN': acc_NB_NN,
        'acc_NB_NN_INFO': str(acc_NB_NN_INFO),
        'acc_NB_TCA': acc_NB_TCA,
        'acc_NB_TCA_INFO': str(acc_NB_TCA_INFO),
        'acc_NB_SA': acc_NB_SA,
        'acc_NB_SA_INFO': str(acc_NB_SA_INFO)
    }])
コード例 #10
0
def test_init():
    """Test for object type."""
    clf = TransferComponentClassifier()
    assert type(clf) == TransferComponentClassifier
    assert not clf.is_trained
コード例 #11
0
ファイル: Domain_Adaptation.py プロジェクト: pegahani/REUS
    def DoA(self, sampling_times, blind_sampling):

        #************************************
        accuracy_majority = {
            label: 0.0
            for label in range(self.n_taxonomy_target)
        }
        total_accuracy = 0.0
        total_accuracy_weighted = 0.0
        accuracy_majority_list = {
            label: []
            for label in range(self.n_taxonomy_target)
        }
        total_accuracy_list = []
        total_accuracy_weighted_list = []
        counter_loop = 0
        #************************************

        (all_meeting_input_source, meeting_input_source
         ) = self.text_represent_source.reload_abreviated_labels()
        (all_meeting_input_target, meeting_input_target
         ) = self.text_represent_target.reload_abreviated_labels()

        train_test_data_source = train_test_prep(
            meeting_input=meeting_input_source,
            meeting_group=self.meeting_group_source,
            n_taxonomy=self.n_taxonomy_source,
            blind_samling=blind_sampling,
            sampling=self.sampling_source,
            text_represent=self.text_represent_source,
            which_percentage=self.which_percentage_source)

        train_test_data_target = train_test_prep(
            meeting_input=meeting_input_target,
            meeting_group=self.meeting_group_target,
            n_taxonomy=self.n_taxonomy_target,
            blind_samling=True,
            sampling=self.sampling_target,
            text_represent=self.text_represent_target,
            which_percentage=None)

        train_index_source = [i for i in range(len(self.meeting_group_source))]
        train_index_target = [i for i in range(len(self.meeting_group_target))]

        (train_source, real_label_train_source, test_source, num_sample_source) = train_test_data_source.prepare_train_test_data \
            (train_index=train_index_source, test_index=None, is_smote=False, smote_kind=None, num_sample = None )

        (train_target, real_label_train_target, test_target,
         num_sample_target) = train_test_data_target.prepare_train_test_data(
             train_index=train_index_target,
             test_index=None,
             is_smote=False,
             smote_kind=None,
             num_sample=num_sample_source)

        X_train_sorce = [
            self.meeting_group_source[p] for p in train_index_source
        ]
        X_train_target = [
            self.meeting_group_target[p] for p in train_index_target
        ]

        real_label_target = sum(
            [meeting_input_target[i][1] for i in X_train_target], [])
        predicted_labels_ = [[] for i in real_label_train_target]

        classifier = None
        "learning part"
        start = time.time()
        if self.classifier_type == 'TCA':
            classifier = TransferComponentClassifier()
        elif self.classifier_type == 'SCL':
            classifier = StructuralCorrespondenceClassifier(loss='logistic',
                                                            l2=1.0,
                                                            num_pivots=6,
                                                            num_components=6)

        train_source_array = np.asarray(train_source)
        train_target_array = np.asarray(train_target)

        classifier.fit(train_source_array, real_label_train_source,
                       train_target_array)
        target_predict = classifier.predict(train_target_array)

        finish = time.time()
        print(finish - start)

        counter_loop += 1

        for j in range(len(target_predict)):
            predicted_labels_[j].append(target_predict[j])

        predicted_labels = [
            max(set(item), key=item.count) for item in predicted_labels_
        ]
        accuracy_majority = dict(
            Counter(accuracy_majority) + Counter(
                self.eval.get_predicted_error(predicted_labels,
                                              real_label_train_target)))

        real_vs_predicted = self.eval.get_predicted_error(
            predicted_labels, real_label_train_target)
        for i in accuracy_majority_list.keys():
            accuracy_majority_list[i].append(real_vs_predicted[i])

        accuracy = self.eval.get_total_occuracy(predicted_labels,
                                                real_label_train_target)
        accuracy_weighted = self.eval.get_weighted_accuracy(
            predicted_labels, real_label_train_target)
        total_accuracy_weighted_list.append(accuracy_weighted)

        total_accuracy_weighted += accuracy_weighted
        total_accuracy += accuracy
        total_accuracy_list.append(accuracy)

        #print(self.n_taxonomy_target, ";", num_sample_target, ";", counter_loop, ";", accuracy_weighted, ";",
        #      accuracy, ";", accuracy_majority)

        for sampling in range(sampling_times - 1):

            (train_source, real_label_train_source, test_source, num_sample_source) = train_test_data_source.prepare_train_test_data\
                (train_index= train_index_source, test_index= None, is_smote=False, smote_kind=None, num_sample= None)

            (train_target, real_label_train_target, test_target,
             num_sample_target
             ) = train_test_data_target.prepare_train_test_data(
                 train_index=train_index_target,
                 test_index=None,
                 is_smote=False,
                 smote_kind=None,
                 num_sample=num_sample_source)

            "learning part"
            start = time.time()

            if self.classifier_type == 'TCA':
                classifier = TransferComponentClassifier()
            elif self.classifier_type == 'SCL':
                classifier = StructuralCorrespondenceClassifier(
                    loss='logistic', l2=1.0, num_pivots=6, num_components=6)

            train_source_array = np.asarray(train_source)
            train_target_array = np.asarray(train_target)

            classifier.fit(train_source_array, real_label_train_source,
                           train_target_array)
            target_predict = classifier.predict(train_target_array)

            finish = time.time()
            print(finish - start)

            for j in range(len(target_predict)):
                predicted_labels_[j].append(target_predict[j])

            predicted_labels = [
                max(set(item), key=item.count) for item in predicted_labels_
            ]
            accuracy_majority = dict(
                Counter(accuracy_majority) + Counter(
                    self.eval.get_predicted_error(predicted_labels,
                                                  real_label_train_target)))

            real_vs_predicted = self.eval.get_predicted_error(
                predicted_labels, real_label_train_target)
            for i in accuracy_majority_list.keys():
                accuracy_majority_list[i].append(real_vs_predicted[i])

            accuracy = self.eval.get_total_occuracy(predicted_labels,
                                                    real_label_train_target)
            accuracy_weighted = self.eval.get_weighted_accuracy(
                predicted_labels, real_label_train_target)
            total_accuracy_weighted_list.append(accuracy_weighted)

            total_accuracy_weighted += accuracy_weighted
            total_accuracy += accuracy
            total_accuracy_list.append(accuracy)

            # print(self.n_taxonomy_target, ";", num_sample_target, ";", counter_loop, ";", accuracy_weighted, ";",
            #       accuracy,";", accuracy_majority)

            counter_loop += 1

        accurancy_majority_ = {
            key: accuracy_majority[key] / counter_loop
            for key in accuracy_majority.keys()
        }

        print('*************************************')

        print(self.n_taxonomy_target, ";", num_sample_target, ";",
              total_accuracy_weighted / counter_loop, ";",
              total_accuracy / counter_loop, ";", accurancy_majority_)

        return self.n_taxonomy_target, ";", num_sample_target, ";", total_accuracy_weighted / counter_loop, ";",\
               total_accuracy / counter_loop, ";", accurancy_majority_