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