如何用LSTM预测未来60天的股价?

时间:2019-12-30 14:12:08

标签: machine-learning deep-learning lstm recurrent-neural-network lstm-stateful

df = df['Close'].values
df = df.reshape(-1,1)
dataset_train = np.array(df[:int(df.shape[0]*0.8)])
dataset_test = np.array(df[int(df.shape[0]*0.8)-50:])
scaler = MinMaxScaler(feature_range=(0,1))
dataset_train = scaler.fit_transform(dataset_train)

#
def create_my_dataset(df):
x = []
y = []
for i in range(50,df.shape[0]):
    x.append(df[i-50:i,0])
    y.append(df[i,0])
    x = np.array(x)
    y = np.array(y)
    return x,y

 x_train, y_train = create_my_dataset(dataset_train)
 x_test, y_test = create_my_dataset(dataset_test)
 x_train = np.reshape(x_train, (x_train.shape[0],x_train.shape[1],1))
 x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1],1))

tf.logging.set_verbosity(tf.logging.ERROR)
model = Sequential()
model.add(LSTM(units= 100, return_sequences=True, input_shape=(x_train.shape[1],1)))
model.add(Dropout(0.2))
model.add(LSTM(units= 100, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units= 100))
model.add(Dropout(0.2))
model.add(Dense(units=1))

model.compile(loss='mean_squared_error', optimizer ='adam')
model.fit(x_train, epochs=50, batch_size=32)

所以我开发了一个非常简单的代码,从2010年1月1日至2019年11月19日以lstm收盘价 我想做的就是找出该模型可以预测的2020年1月10日。我将如何做?

0 个答案:

没有答案