예제 #1
0
def main():
    opt = parse_arg()
    print('')
    print(opt)
    x_batches, y_batches, img_count = func.prep_data(opt.currency,
                                                     opt.days_ahead)
    trainset_full, testset = func.test_data(x_batches, y_batches, opt.split,
                                            img_count)

    func.change_dir(opt.CNN_only, opt.currency, opt.days_ahead)
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    model = func.prep_model(opt.CNN_only,
                            n_tree=opt.n_tree,
                            tree_depth=opt.tree_depth,
                            tree_feature_rate=opt.tree_feature_rate)

    model = model.to(device)

    optim = func.prep_optim(model, opt.optimizer)

    train_loss, val_loss, class_err, roc, auc, conf_mat = func.training(
        model, opt.CNN_only, opt.batch_size, opt.epochs, device, optim,
        trainset_full, testset)
    accuracy = 1 - class_err

    print("accuracy on testset", round(100 * accuracy), "%")
    print("AUC testset", round(auc, 3))
    print("confusion matrix", conf_mat)

    test_results = dict(auc=auc, accuracy=accuracy)

    with open('test_results.csv', 'w') as f:
        w = csv.DictWriter(f, test_results.keys())
        w.writeheader()
        w.writerow(test_results)

    with open('conf_mat.csv', 'w') as f:
        w = csv.DictWriter(f, conf_mat.keys())
        w.writeheader()
        w.writerow(conf_mat)

    tpr = roc[0]
    fpr = roc[1]
    roc_curve = [tpr, fpr]

    with open("roc_curve.csv", 'w') as f:
        writer = csv.writer(f)
        writer.writerows(roc_curve)

    # Print the console output
    sys.stout = open("arguments.txt", "w")
    print(opt, file=sys.stout)
예제 #2
0
import glob
import os
import functions as func

def parse_arg():
    parser = argparse.ArgumentParser()
    parser.add_argument('-currency', choices=['EURUSD', 'USDJPY', 'GBPUSD'], type=str, default="EURUSD")
    parser.add_argument('-CNN_only', action='store_true')
    parser.add_argument('-days_ahead', type=int, default=1)
    opt = parser.parse_args()

    return opt

opt = parse_arg()

func.change_dir(opt.CNN_only, opt.currency, opt.days_ahead)

path = os.getcwd()
all_results = glob.glob(path + '/*.csv')

try:
    all_results.remove(path + '/val_results_full.csv')
except:
    pass

try:
    all_results.remove(path + '/roc_curve.csv')
except:
    pass

try:
예제 #3
0
     name_of_dir = input("Введите имя папки: ")
     os.mkdir(name_of_dir)
 elif choice == '2':
     functions.remove_file_or_dir()
 elif choice == '3':
     functions.copy_file_or_dir()
 elif choice == '4':
     cwd = os.getcwd()
     print(os.listdir(path=cwd))
 elif choice == '5':
     print(functions.print_dirs())
 elif choice == '6':
     print(functions.print_files())
 elif choice == '7':
     print(platform.uname())
 elif choice == '8':
     print(functions.info_about_creator())
 elif choice == '9':
     victory()
 elif choice == '10':
     account_f()
 elif choice == '11':
     new_path = input("Введите путь к желаемой директории: ")
     functions.change_dir(new_path)
 elif choice == '12':
     functions.save_fails_and_dirs()
 elif choice == '13':
     functions.exit()
     break
 else:
     print('Неверный пункт меню')
예제 #4
0
 functions.display()
 choice = input('Выберите пункт меню')
 if choice == '1':
     name_of_dir = input("Введите имя папки: ")
     os.mkdir(name_of_dir)
 elif choice == '2':
     functions.remove_file_or_dir()
 elif choice == '3':
     functions.copy_file_or_dir()
 elif choice == '4':
     cwd = os.getcwd()
     print(os.listdir(path=cwd))
 elif choice == '5':
     functions.print_dirs()
 elif choice == '6':
     functions.print_files()
 elif choice == '7':
     print(platform.uname())
 elif choice == '8':
     functions.info_about_creator()
 elif choice == '9':
     victory()
 elif choice == '10':
     account()
 elif choice == '11':
     functions.change_dir()
 elif choice == '12':
     exit()
     break
 else:
     print('Неверный пункт меню')
예제 #5
0
    elif choice == '6':
        functions.list_file()  # файлы рабочей дирректории

    elif choice == '7':
        functions.list_folders()  # папки рабочей дирректории

    elif choice == '8':
        print('Информация об ОС:')
        print(platform.uname())  # информация об ОС

    elif choice == '9':
        print('Создатель программы: Шаров Игорь')  # автор программы

    elif choice == '10':  # викторина
        print('Викторина')
        victory.victory()

    elif choice == '11':  # банковский счет
        print('Мой банковский счет. Меню:')
        use_functions.banks()

    elif choice == '11':
        functions.change_dir()  # смена рабочей дирректории

    elif choice == '0':
        print('Вы вышли из программы')
        break
    else:
        print('Вы ввели неверный пункт меню')
예제 #6
0
def test_change_dir():
    old_onlydirs = functions.print_dirs()
    functions.change_dir("C:/Users/Ольга")
    new_onlydirs = functions.print_dirs()
    assert old_onlydirs != new_onlydirs
예제 #7
0
def main():
    opt = parse_arg()
    print('')
    print('CNN_only:', opt.CNN_only, ', currency:', opt.currency,
          ', train/valset split:', opt.split)

    x_batches, y_batches, img_count = func.prep_data(opt.currency,
                                                     opt.days_ahead)
    trainset_val, valset = func.validation_data(x_batches, y_batches,
                                                opt.split, img_count)

    func.change_dir(opt.CNN_only, opt.currency, opt.days_ahead)
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    grid = func.prep_grid(opt.CNN_only, opt.grid_nr)
    print('')
    print("testing", grid.shape[0],
          "hyperparameter combinations in gridsearch")
    results = []

    for i in range(len(grid)):
        hyparams = grid.loc[i]
        print('')
        print(grid.loc[[i]])
        batch_size = int(hyparams['batch_size'])
        epochs = int(hyparams['epochs'])
        optimizer = str(hyparams['optimizer'])

        if opt.CNN_only:
            n_tree = 'n/a'
            tree_depth = 'n/a'
            tree_feature_rate = 'n/a'
        else:
            n_tree = int(hyparams['n_tree'])
            tree_depth = int(hyparams['tree_depth'])
            tree_feature_rate = float(hyparams['feature_rate'])

        model = func.prep_model(opt.CNN_only,
                                n_tree=n_tree,
                                tree_depth=tree_depth,
                                tree_feature_rate=tree_feature_rate)

        model = model.to(device)
        optim = func.prep_optim(model, optimizer)

        train_loss, val_loss, class_err, roc, auc, conf_mat = func.training(
            model, opt.CNN_only, batch_size, epochs, device, optim,
            trainset_val, valset)

        result_temp = [train_loss, val_loss, class_err, auc]
        print("class_err", round(class_err, 3), ", AUC:", round(auc, 3))
        results.append(result_temp)

    header_results = ['train_loss', 'val_loss', 'class_err', 'auc']
    results = pd.DataFrame(results, columns=header_results)

    grid_results = pd.concat([grid, results], axis=1)
    grid_results = grid_results.sort_values("class_err", ascending=True)
    name = "val_results_batch_" + str(opt.grid_nr) + ".csv"
    grid_results.to_csv(name, encoding='utf-8', index=False)

    print("runtime complete:", datetime.now() - startTime)