我想创建一个LSTM模型,它以股票市场信息为输入,以预测价格为输出。
x_train的形状为(35676,10,10),x_test的形状为(8920,10,10),y_train的形状为(35676,1),y_test的形状为(8920,1)。
当我用x_train和y_train拟合模型时,输出预测的形状为(8920,11),而不是(8920,1)。
\#spliting data
split_lmt = int(len(x)\*0.8)
x_train, x_test = x\[:split_lmt\], x\[split_lmt:\]
y_train, y_test = y\[:split_lmt\], y\[split_lmt:\]
\#lstm model
lstm_input = Input(shape=(10,10), name='LSTM_input')
inputs = LSTM(80, name='firtst_layer')(lstm_input)
inputs = Dense(1, name='dence_layer')(inputs)
output = Activation('linear', name='output')(inputs)
model = Model(inputs=lstm_input, outputs=output)
adam = optimizers.Adam()
model.compile(optimizer=adam, loss='mse')
model.fit(x_train, y_train, batch_size=15, epochs=30, shuffle=False, validation_split=0.1)
y_pred = model.predict(x_test)
pred_copy = np.repeat(y_pred, tf2.shape\[1\], axis=-1)
y_pred = sc.inverse_transform(pred_copy)
print(x_train.shape)
print(x_test.shape)
print(y_train.shape)
print(y_test.shape)
print(y_pred.shape)
\#output
(35676, 10, 10)
(8920, 10, 10)
(35676, 1)
(8920, 1)
(8920, 11)
我不知道是什么引起的,你知道吗?
1条答案
按热度按时间6g8kf2rb1#
问题是在这里
pred_copy = np.repeat(y_pred, tf2.shape\[1\], axis=-1)
.idk什么是tf2
。你应该张贴完成的代码。在我跑完之后
y_pred
大小是(8920, 1)
下面是上面代码的输出: