Python 为什么LSTM模型的预测值显示平行线不符合趋势
->创建LSTM模型的源代码Python 为什么LSTM模型的预测值显示平行线不符合趋势,python,tensorflow,keras,lstm,stock,Python,Tensorflow,Keras,Lstm,Stock,->创建LSTM模型的源代码 def create_model(learning_rate, num_dense_layers,num_input_nodes, num_dense_nodes, activation, adam_decay): model = Sequential() model.add(LSTM(units = num_input_nodes, input_shape= (30,4), activation=activation,
def create_model(learning_rate, num_dense_layers,num_input_nodes,
num_dense_nodes, activation, adam_decay):
model = Sequential()
model.add(LSTM(units = num_input_nodes, input_shape= (30,4), activation=activation, return_sequences=True))
model.add(LSTM(units = 10, activation=activation))
for i in range(num_dense_layers):
name = 'layer_dense_{0}'.format(i+1)
model.add(Dense(num_dense_nodes,
activation=activation,
name=name
))
model.add(Dense(units=1))
adam = Adam(lr=learning_rate, decay= adam_decay)
loss=Huber()
model.compile(optimizer=adam, loss=loss)
return model
->利用高斯过程(GP)方法得到了LSTM机的最优超参数,并将其用于建模
gp_result = [0.001, 1, 512, 13, 'relu', 64, 0.001]
#call our best model
gp_model = create_model(gp_result.x[0],gp_result.x[1],gp_result.x[2],gp_result.x[3],gp_result.x[4],gp_result.x[5])
gp_model.summary()
gp_model.fit(X_train,y_train, epochs=500)
gp_model.evaluate(X_test,y_test)
->这里,X_序列是由(570,30,4)3-d阵列组成的数据。y_序列由(570,1)二维阵列组成。若为y_列,则由(100,30,4)组成,y_测试为(100,1)。
X数据是指4个特征的30天数据(开盘时的股价、当日最高价格、当日最低价格和当日交易量),y数据是指第二天的结果(收盘时的股价)
模型摘要 图层(类型)输出形状参数# lstm(lstm)(无,30512)1058816
lstm_1(lstm)(无,10)20920
第1层致密(致密)(无,13)143
致密(致密)(无,1)14
->最后的结果就在这里 我不明白为什么模型的预测不能跟随股票价格。我使用贝叶斯优化和高斯过程来寻找损失最小的超参数。在应用贝叶斯模型之前,我使用了简单的模型 这个,这个模型呢,大致跟随着股票的价格,, 上图是预测数据图(model.predict(X_检验))和实际数据图(y_检验) 我不明白为什么会这样。 有人能帮我吗? 我想提前表达我的谢意
gp_model.fit(X_train,y_train, epochs=1000, verbose=0)
gp_model.evaluate(X_test,y_test)
pred = gp_model.predict(X_test)
pred.shape
import matplotlib.pyplot as plt
plt.plot(pred)
plt.plot(y_test)
plt.xlabel('day')
plt.ylabel('price')