我正在研究一个有状态的 LSTM 来预测股票价格。
这些是我的输入数据的形状:(更新)
x_train = (10269, 300, 89)
y_train = (10269, 1)
x_test = (4401, 300, 89)
y_test = (4401, 1)
这是我的模型初始化:
batch_size = 63
timesteps = x_train.shape[1]
data_dim = x_train.shape[2]
model = Sequential()
model.add(LSTM(32, return_sequences=True, batch_input_shape=(batch_size, timesteps, data_dim), stateful=True))
model.add(LSTM(32, return_sequences=True, stateful=True))
model.add(LSTM(32, stateful=True))
model.add(Dense(1))
model.compile(optimizer = 'adam', loss = 'mean_squared_error')
但是当我适合这个时,我得到了错误:
InvalidArgumentError: Specified a list with shape [64,89] from a tensor with shape [29,89]
[[{{node TensorArrayUnstack/TensorListFromTensor}}]]
[[sequential/lstm/PartitionedCall]] [Op:__inference_train_function_6536]
据我所知,我已经正确定义了 batch_input_shape 并且看不到我做错了什么。
编辑:
一些人建议我尝试让我的样本大小可以被我的批量大小整除。我试过了,得到了同样的错误。
(如上所示,我更新了我的训练和测试大小)
我的新批量大小为 63,数据大小为 10269。10269/63 = 163。这是错误:
InvalidArgumentError: Specified a list with shape [63,89] from a tensor with shape [54,89]
[[{{node TensorArrayUnstack/TensorListFromTensor}}]]
[[sequential_1/lstm_3/PartitionedCall]] [Op:__inference_test_function_20179]