Exemplo n.º 1
0
def run_recommand_system(root_path, train_symbols, predict_symbols, need_training, need_plot_training_diagram, need_predict):
    paras = SP_Paras('recommandSystem', root_path, train_symbols, predict_symbols)
    paras.save = True
    paras.load = False
    paras.run_hyperopt = True
    paras.plot = need_plot_training_diagram

   
    paras.features = {'1_0_0':['week_day'],
                      '1_0_1':['c_2_o', 'h_2_o', 'l_2_o', 'c_2_h', 'h_2_l', 'vol_p'],
                      '1_1_0':['buy_amount', 'sell_amount', 'even_amount'],
                      '1_1_1':['buy_volume', 'sell_volume', 'even_volume'], 
                      '1_1_2':['buy_max', 'buy_min', 'buy_average', 'sell_max', 'sell_min', 'sell_average', 'even_max', 'even_min', 'even_average']} 
    
    paras.window_len = [3]
    paras.pred_len = 1
    paras.valid_len = 20
    paras.start_date = '2016-11-01'
    paras.end_date = datetime.datetime.now().strftime("%Y-%m-%d")
    paras.verbose = 0
    paras.batch_size = 64
    paras.epoch = 200
    paras.out_class_type = 'classification'
    paras.n_out_class = 7  # ignore for regression

    rs = recommand_system(paras)
    rs.run(need_training, need_predict)
def run_xgboost_classification(root_path, need_training,
                               need_plot_training_diagram, need_predict):
    df = getStocksList_CHN(root_path)
    df.index = df.index.astype(str).str.zfill(6)
    df = df.sort_index(ascending=True)
    predict_symbols = df.index.values.tolist()

    paras = SP_Paras('xgboost', root_path, predict_symbols, predict_symbols)
    paras.save = True
    paras.load = False
    paras.run_hyperopt = True
    paras.plot = need_plot_training_diagram

    # A_B_C format:
    # A: require window split or not -> 0 for not, 1 for yes
    # B: normalization method -> 0: none 1: standard 2: minmax 3: zscore
    # C: normalization index, same normalization requires different index
    paras.features = {
        '0_0_0': ['week_day'],
        '1_0_1': ['c_2_o', 'h_2_o', 'l_2_o', 'c_2_h', 'h_2_l', 'vol_p'],
        '1_1_0': ['buy_amount', 'sell_amount', 'even_amount'],
        '1_1_1': ['buy_volume', 'sell_volume', 'even_volume'],
        '1_1_2': [
            'buy_max', 'buy_min', 'buy_average', 'sell_max', 'sell_min',
            'sell_average', 'even_max', 'even_min', 'even_average'
        ]
    }

    paras.window_len = [3]
    paras.pred_len = 1
    paras.valid_len = 20
    paras.start_date = '2016-11-01'
    paras.end_date = datetime.datetime.now().strftime("%Y-%m-%d")
    paras.verbose = 1
    paras.batch_size = 64
    paras.epoch = 5000
    paras.out_class_type = 'classification'
    paras.n_out_class = 7  # ignore for regression

    from hyperopt import hp
    paras.hyper_opt = {
        "max_depth": hp.randint("max_depth", 10),
        "n_estimators": hp.randint("n_estimators",
                                   20),  #[0,1,2,3,4,5] -> [50,]
        "gamma": hp.randint("gamma", 4),  #0-0.4
        "learning_rate": hp.randint("learning_rate",
                                    6),  #[0,1,2,3,4,5] -> 0.05,0.06
        "subsample": hp.randint("subsample",
                                4),  #[0,1,2,3] -> [0.7,0.8,0.9,1.0]
        "min_child_weight": hp.randint("min_child_weight", 5),
    }

    # run
    xgboost_cla = xgboost_classification(paras)
    xgboost_cla.run(need_training, need_predict)
    return paras
def run_recommand_system(root_path, train_symbols, predict_symbols,
                         need_training, need_plot_training_diagram,
                         need_predict):
    paras = SP_Paras('recommandSystem', root_path, train_symbols,
                     predict_symbols)
    paras.save = True
    paras.load = False
    paras.run_hyperopt = True
    paras.plot = need_plot_training_diagram

    # A_B_C format:
    # A: require window split or not -> 0 for not, 1 for yes
    # B: normalization method -> 0: none 1: standard 2: minmax 3: zscore
    # C: normalization index, same normalization requires different index
    paras.features = {
        '1_0_0': ['week_day'],
        '1_0_1': ['c_2_o', 'h_2_o', 'l_2_o', 'c_2_h', 'h_2_l', 'vol_p'],
        '1_1_0': ['buy_amount', 'sell_amount', 'even_amount'],
        '1_1_1': ['buy_volume', 'sell_volume', 'even_volume'],
        '1_1_2': [
            'buy_max', 'buy_min', 'buy_average', 'sell_max', 'sell_min',
            'sell_average', 'even_max', 'even_min', 'even_average'
        ]
    }

    paras.window_len = [3]
    paras.pred_len = 1
    paras.valid_len = 20
    paras.start_date = '2016-11-01'
    paras.end_date = datetime.datetime.now().strftime("%Y-%m-%d")
    paras.verbose = 0
    paras.batch_size = 64
    paras.epoch = 200
    paras.out_class_type = 'classification'
    paras.n_out_class = 7  # ignore for regression

    # run
    rs = recommand_system(paras)
    rs.run(need_training, need_predict)
Exemplo n.º 4
0
def run_lstm_classification(root_path, need_training, need_plot_training_diagram, need_predict):
    df = getStocksList_CHN(root_path)
    df.index = df.index.astype(str).str.zfill(6)
    df = df.sort_index(ascending = True)
    predict_symbols = df.index.values.tolist()

    paras = SP_Paras('lstm', root_path, predict_symbols, predict_symbols)
    paras.save = True
    paras.load = False
    paras.run_hyperopt = True
    paras.plot = need_plot_training_diagram

    # A_B_C format:
    # A: require window split or not -> 0 for not, 1 for yes
    # B: normalization method -> 0: none 1: standard 2: minmax 3: zscore
    # C: normalization index, same normalization requires different index
    paras.features = {'1_0_0':['week_day'], # 1
                      '1_0_1':['c_2_o', 'h_2_o', 'l_2_o', 'c_2_h', 'h_2_l', 'vol_p'],  # 5
                      '1_1_0':['buy_amount', 'sell_amount', 'even_amount'], # 3
                      '1_1_1':['buy_volume', 'sell_volume', 'even_volume'], # 3
                      '1_1_2':['buy_max', 'buy_min', 'buy_average', 'sell_max', 'sell_min', 'sell_average', 'even_max', 'even_min', 'even_average']} # 9

    paras.pred_len = 1
    paras.valid_len = 20
    paras.start_date = '2016-11-01'
    paras.end_date = datetime.datetime.now().strftime("%Y-%m-%d")
    paras.verbose = 1
    
    paras.out_class_type = 'classification'
    paras.n_out_class = 7  # ignore for regression
    paras.epoch = 1000

    paras.window_len = [5]
    paras.batch_size = 64
    paras.model['hidden_layers'] = [210, 140, 210, 140, 210, 140, 70]
    paras.model['dropout'] = 0.5
    paras.model['activation'] = 'relu'
    paras.model['optimizer'] = 'adam'
    paras.model['learning_rate'] = 0.01

    paras.model['out_activation'] = 'softmax'
    paras.model['out_layer'] = paras.n_out_class
    paras.model['loss'] = 'categorical_crossentropy'

    from hyperopt import hp
    paras.hyper_opt = {"batch_size_opt"   :[32, 64, 128],
                       "activation_opt"   :['relu', 'tanh', 'sigmoid'],
                       "optimizer_opt"    :['sgd', 'rmsprop', 'adagrad', 'adam'],
    }

    paras.hyper_opt.update({
                       "batch_size"       :hp.choice ("batch_size"   , paras.hyper_opt['batch_size_opt'] ), 
                       "dropout"          :hp.uniform("dropout"      , 0.3, 0.7     ), 
                       "learning_rate"    :hp.uniform("learning_rate", 0.005, 0.02  ),  
                       "activation"       :hp.choice ("activation"   , paras.hyper_opt['activation_opt']), 
                       "optimizer"        :hp.choice ("optimizer"    , paras.hyper_opt['optimizer_opt']), 
    })

   
    lstm_cla = rnn_lstm_classification(paras)
    lstm_cla.run(need_training, need_predict)
    return paras