コード例 #1
0
def main(config):
    logger = load_logger(config)
    try:
        np.random.seed(config.random_seed)  # 设置随机种子
        data_gainer = Data(config)

        if config.do_train:
            train_X, valid_X, train_Y, valid_Y = data_gainer.get_train_and_valid_data(
            )
            train(config, logger, [train_X, train_Y, valid_X, valid_Y])

        if config.do_predict:
            test_X, test_Y, test_date = data_gainer.get_test_data(
                return_label_data=True)
            pred_result = predict(config, test_X)
            pred_result = [np.argwhere(i == max(i)) for i in pred_result]
            pred_result = np.squeeze(pred_result)
            test_Y = np.squeeze(test_Y)
            draw(config, data_gainer, logger, pred_result, test_Y, test_date)
            #save_predict(config,pred_result,test_date)

        if config.do_predict_all:
            test_X, test_date = data_gainer.get_test_data(
                return_label_data=False, predict_all=True)
            pred_result = predict(config, test_X)
            pred_result = [np.argwhere(i == max(i)) for i in pred_result]
            pred_result = np.squeeze(pred_result)
            #draw(config, data_gainer, logger, pred_result, test_Y,test_date)
            save_predict(config, pred_result, test_date)
    except Exception:
        logger.error("Run Error", exc_info=True)
コード例 #2
0
def main(config):
    logger = load_logger(config)
    try:
        np.random.seed(config.random_seed)  # 设置随机种子,保证可复现
        data_gainer = Data(config)

        if config.do_train:
            train_X, valid_X, train_Y, valid_Y = data_gainer.get_train_and_valid_data(
            )
            train(config, logger, [train_X, train_Y, valid_X, valid_Y])

        if config.do_predict:
            test_X, test_Y = data_gainer.get_test_data()
            pred_ys, real_ys, pred_ys_no_flat = predict(
                config, [test_X, test_Y])
            target_names = ['class flat', 'class down',
                            'class rise']  # label: 0:平  1:跌  2:涨
            print('Classification table for test set:')
            print(
                classification_report(real_ys,
                                      pred_ys,
                                      target_names=target_names))
            # draw(config, data_gainer, logger, pred_result)
    except Exception:
        logger.error("Run Error", exc_info=True)
コード例 #3
0
def main(config):
    np.random.seed(config.random_seed)
    data_gainer = Data(config)

    if config.do_train:
        train_X, valid_X, train_Y, valid_Y = data_gainer.get_train_and_valid_data(
        )
        train(config, train_X, train_Y, valid_X, valid_Y)

    if config.do_predict:
        test_X, test_Y = data_gainer.get_test_data(return_label_data=True)
        pred_result = predict(config, test_X)
        draw(config, data_gainer, pred_result)
コード例 #4
0
def main(config):
    logger = load_logger(config)
    try:
        np.random.seed(config.random_seed)  # 设置随机种子,保证可复现
        data_gainer = Data(config)

        if config.do_train:
            train_X, valid_X, train_Y, valid_Y = data_gainer.get_train_and_valid_data()
            train(config, logger, [train_X, train_Y, valid_X, valid_Y])

        if config.do_predict:
            test_X, test_Y = data_gainer.get_test_data(return_label_data=True)
            pred_result = predict(config, test_X)  # 这里输出的是未还原的归一化预测数据
            draw(config, data_gainer, logger, pred_result)
    except Exception:
        logger.error("Run Error", exc_info=True)
コード例 #5
0
ファイル: main.py プロジェクト: middleprince/lab-lstm
def main(config):
    logger = load_logger(config)
    try:
        np.random.seed(config.random_seed)
        data_gainer = Data(config)

        if config.do_train:
            train_X, train_Y = data_gainer.get_dataset('train')
            valid_X, valid_Y = data_gainer.get_dataset('val')
            train(config, logger, [train_X, train_Y, valid_X, valid_Y])

        if config.do_predict:
            test_X, test_Y = data_gainer.get_test_data(return_label_data=True)
            pred_result = predict(config, test_X)
            # TODO:save prediction result into csv file
            save_prediction_data(config, data_gainer, pred_result)
            #draw(config, data_gainer, logger, pred_result)
    except Exception:
        logger.error("Run Error", exc_info=True)