Ejemplo n.º 1
0
def main():

    # set path
    iris_path = [
        'DataAnalysisProjectDesign/Experiment1/iris_train.arff',
        'DataAnalysisProjectDesign/Experiment1/iris_test.arff'
    ]
    adult_path = [
        'DataAnalysisProjectDesign/Experiment1/adult_train.arff',
        'DataAnalysisProjectDesign/Experiment1/adult_test.arff'
    ]

    # get choice
    data_choice = input('Enter 1 for iris DT; Enter 2 for adult DT:')
    tree_choice = input('Enter 1 for ID3; Enter 2 for CART:')

    path = select_dataset(data_choice, iris_path, adult_path)

    # create train data instance
    train_data_obj = Data(path[0])
    train_data_obj.load_data()
    train_data_obj.fill_missing_data()
    # create test data instance
    test_data_obj = Data(path[1])
    test_data_obj.clear_memory()
    test_data_obj.load_data()
    test_data_obj.fill_missing_data()

    tree = dt_router(train_data_obj, test_data_obj, tree_choice)

    tree.test()

    conf_mat, judge = tree.get_conf_mat()

    return tree, conf_mat, judge
Ejemplo n.º 2
0
def main():
    
    # set path
    iris_path = 'DataAnalysisProjectDesign/Experiment2/iris_train.arff'
    adult_path = 'DataAnalysisProjectDesign/Experiment2/adult_train.arff'

    # get choice
    data_choice = input('Enter 1 for iris; Enter 2 for adult:')

    dt_num = int(input('Enter your expected tree number:'))

    path = select_dataset(data_choice,iris_path,adult_path)

    # create data instance
    data_obj = Data(path)
    data_obj.load_data()
    data_obj.fill_missing_data()

    # create random forest
    rf = RandomForest(
        data=data_obj,
        dt_num=dt_num
    )

    rf.bagging()
    rf.train_rf()
    correct_rate,conf_mat = rf.test_rf()

    return dt_num,correct_rate,conf_mat
Ejemplo n.º 3
0
def main():

    path = 'DM_Experiment4/iris.arff'

    choice = input('Use KMeans Enter 1;Use DBSCAN Enter 2:')

    # load data
    data_obj = Data(path=path)
    data_obj.load_data()

    algorithm_router(choice, data_obj)
Ejemplo n.º 4
0
def run_model():
    d = Data(LANG, DEVorTEST, GLOVE_FILE, ELMO_FILE, MODEL, DEP_ADJACENCY_GCN,
             POSITION_EMBED)
    d.load_data(
        DATAPATH
    )  # This loads train, dev, and test if available, and also word2vec and ELMo where relevant

    model = Tagger(d, d.max_length, d.input_dim, d.n_poses, d.n_classes,
                   initial_weight)
    tagger = getattr(model, MODEL)()  # choose the specified tagging model

    T = Train_Test(POS, MODEL, tagger, d)
    if DEVorTEST == "CROSS_VAL":
        T.cross_validation(EPOCHS, BATCH_SIZE, DATAPATH)
    else:
        T.train(EPOCHS, BATCH_SIZE)
        T.test(DATAPATH
               )  # We pass DATAPATH to this function to be used for evaluation
Ejemplo n.º 5
0
def run_model():
    # args: lang, train, dev, test, word2vec_dir, elmo_dir, model_name
    d = Data(LANG_TR, LANG_DEV, LANG_TS, DEVorTEST, WV_DIR, ELMO_PATH, MODEL,
             DEP_ADJACENCY_GCN, DEP_INFO, POS)
    d.load_data(
        DATAPATH
    )  # This loads train, dev (if available), test (if available) and also word2vec and ELMo

    # args: max_length, n_poses, n_classes, initial_weight=''
    model = Tagger(d, initial_weight)
    tagger = getattr(model, MODEL)()  # choose the specified tagging model
    print(tagger)

    T = Train_Test(POS, W2V, MODEL, tagger, d, DEVorTEST)
    if DEVorTEST == "CROSS_VAL":
        T.cross_validation(EPOCHS, BATCH_SIZE, DATAPATH)
    else:
        T.train(EPOCHS, BATCH_SIZE)
        T.test(
            DATAPATH
        )  # We give the Data_path to this function, just for it to return the evaluation for us