示例#1
0
def test_minimax_normalization_ones():
    _tca = tca_plus.TCAPlus(test_set_X=pd.DataFrame(np.ones((5, 5))),
                            test_set_domain=1,
                            train_pool_X=pd.DataFrame(np.ones((5, 5))),
                            train_pool_y=None,
                            train_pool_domain=[0, 0, 0, 1, 1],
                            Base_Classifier=None)
    print(_tca.minmax_normalization())
示例#2
0
def test_distance():
    _tca = tca_plus.TCAPlus(test_set_X=None,
                            test_set_domain=None,
                            train_pool_X=None,
                            train_pool_y=None,
                            train_pool_domain=None,
                            Base_Classifier=None)
    dist_ = _tca.compute_distance_set(np.random.rand(4, 50))
    print(_tca.compute_dcv(dist_, 4))
示例#3
0
def test_dcv_sim_vector():
    _tca = tca_plus.TCAPlus(test_set_X=None,
                            test_set_domain=None,
                            train_pool_X=None,
                            train_pool_y=None,
                            train_pool_domain=None,
                            Base_Classifier=None)
    dist1 = _tca.compute_distance_set(np.random.rand(4, 50))
    dist2 = _tca.compute_distance_set(np.random.rand(4, 50))
    dcv_1, dcv_2 = _tca.compute_dcv(dist1, 4), _tca.compute_dcv(dist2, 4)
    print(_tca.compute_dist_similarity(dcv_1, dcv_2))
示例#4
0
def test_full():
    X_test = pd.DataFrame(np.random.rand(5, 5))
    X_train = test_set_X = pd.DataFrame(np.ones((5, 5)))
    _tca = tca_plus.TCAPlus(X_test,
                            test_set_domain=1,
                            train_pool_X=X_train,
                            train_pool_y=None,
                            train_pool_domain=[0, 0, 0, 1, 1],
                            Base_Classifier=None)
    dist1 = _tca.compute_distance_set(X_test)
    dist2 = _tca.compute_distance_set(X_train)
    dcv_1, dcv_2 = _tca.compute_dcv(dist1, 4), _tca.compute_dcv(dist2, 4)

    print(_tca.minmax_normalization())
示例#5
0
def test_similarity():
    _tca = tca_plus.TCAPlus(test_set_X=None,
                            test_set_domain=None,
                            train_pool_X=None,
                            train_pool_y=None,
                            train_pool_domain=None,
                            Base_Classifier=None)
    assert _tca.compute_comp_similarity(905,
                                        238) == tca_plus.SimLevel.MUCH_LESS
    assert _tca.compute_comp_similarity(60, 60) == tca_plus.SimLevel.SAME
    assert _tca.compute_comp_similarity(59, 60) == tca_plus.SimLevel.SAME
    assert _tca.compute_comp_similarity(100,
                                        125) == tca_plus.SimLevel.SLIGHTLY_MORE
    assert _tca.compute_comp_similarity(100, 39) == tca_plus.SimLevel.MUCH_LESS
示例#6
0
def test_normalization():
    source_X = pd.DataFrame(np.random.rand(5, 5))
    target_X = pd.DataFrame(np.random.rand(5, 5))

    _tca = tca_plus.TCAPlus(test_set_X=None,
                            test_set_domain=1,
                            train_pool_X=None,
                            train_pool_y=None,
                            train_pool_domain=[0, 0, 0, 1, 1],
                            Base_Classifier=None)
    #print(_tca.minmax_normalization(source_X, target_X))
    print(_tca.zscore_normalization(source_X, target_X))
    print(_tca.zscore_source_normalization(source_X, target_X))
    print(_tca.zscore_target_normalization(source_X, target_X))
示例#7
0
文件: run_cross.py 项目: pa1511/REPDX
                        join="inner").reset_index(drop=True)
                    #============================================================
                    train_pool_domain = [
                        1 if e < len(X_train) else 0
                        for e in range(len(X_train_join))
                    ]
                except:
                    print("Error while preparing data")
                    continue
                #============================================================
                #print("TCA+")
                try:
                    _tca = tca_plus.TCAPlus(
                        test_set_domain=0,
                        train_pool_domain=train_pool_domain,
                        test_set_X=X_test,
                        train_pool_X=X_train_join,
                        train_pool_y=y_train_join,
                        Base_Classifier=LogisticRegression)
                    confidence, y_p = _tca.train_filter_test()
                    accuracy, precision, recall, f1_score = calculate_results(
                        y_test, y_p)

                    #Store results
                    data = [
                        'TCA+', accuracy, precision, recall, f1_score, source,
                        target
                    ]
                    performance_data.append(data)
                except:
                    print("Error while running TCA+")
示例#8
0
test_set_y = test_set.loc[:, ["label"]].reset_index(drop=True)

# gather all non-test indexes
train_pool = all_instances.iloc[
    all_instances.index.difference(test_set.index), ]
train_pool_X = train_pool.loc[:, ["x_coord", "y_coord"]].reset_index(drop=True)
train_pool_y = train_pool["label"].reset_index(drop=True)
train_pool_domain = train_pool.domain_index

# We don't have much training data, but we got some predictions with confidence levels!

transfer_learners = [
    tca_plus.TCAPlus(test_set_X=test_set_X,
                     test_set_domain=test_set_domain,
                     train_pool_X=train_pool_X,
                     train_pool_y=train_pool_y,
                     train_pool_domain=train_pool_domain,
                     Base_Classifier=RandomForestClassifier,
                     rand_seed=RAND_SEED),
    tca.TCA(test_set_X=test_set_X,
            test_set_domain=test_set_domain,
            train_pool_X=train_pool_X,
            train_pool_y=train_pool_y,
            train_pool_domain=train_pool_domain,
            Base_Classifier=RandomForestClassifier,
            rand_seed=RAND_SEED),
    tl_baseline.Source_Baseline(test_set_X=test_set_X,
                                test_set_domain=test_set_domain,
                                train_pool_X=train_pool_X,
                                train_pool_y=train_pool_y,
                                train_pool_domain=train_pool_domain,