如何根据当前收盘价预测未来的多次迭代?凯拉斯 Python

数据挖掘 机器学习 Python 喀拉斯 熊猫 rnn
2022-02-18 03:07:44

我有来自 CoinMarketCap 的比特币收盘价数据。我如何使用这些数据来预测未来的多天,使用过去的日子和一个函数?我希望函数看起来像:

def predict(days, data):
  preds=data[-days*2:]
  for d in days:
     pred=model.predict(preds)
     preds.append(pred)
  return np.array(preds)

我已经有一个训练测试拆分功能和窗口转换器。我的输入数据的形状是(*,1),因此要循环它,我需要我的输出具有确切的形状。

我该怎么做?我的模型在 Keras 中会是什么样子?我必须将数据转换为窗口吗?

到目前为止,这是我的代码:

window_len=30

def train_test_split(df, test_size=0.1):
    split=len(df) - int(test_size * len(df))
    train=df[:split]
    test=df[split:]
    return train, test

def pred_convert_window(df,window_len=window_len):
    windows=[]
    for i in range(len(df)-window_len):
        windows.append(df[i:i+window_len])
    return np.array(windows)

# PRED MODEL IN/OUT
scaler=MinMaxScaler(feature_range=(0,1))
close=scaler.fit_transform(df['close'].values.reshape(-1,1))

train,test=train_test_split(close)

我的close数据形状是(2022,1)

我的traintest数据形状是((1820, 1), (202, 1))

0个回答
没有发现任何回复~