【发布时间】:2020-05-02 04:55:44
【问题描述】:
我有一个数据集,包含过去 7 年的每小时数据。
我正在尝试使用 train 根据所有变量(包括价格)的 168 小时(1 周)历史数据,提前 24 小时预测一个变量(价格)。
为此,我尝试构建一个带有 LSTM 层和时间分布层的 NN,但是我很难理解从每一层返回的数据的形状。
我的代码如下:
X_train.shape, Y_train.shape, X_valid.shape, Y_valid.shape, X_test.shape, Y_test.shape
((43800, 168, 6),
(43800, 24),
(8760, 168, 6),
(8760, 24),
(8574, 168, 6),
(8574, 24))
因此,训练数据 (X) 由 43800 个样本组成,回顾了 168 小时的 6 个特征。 Y 为 43800 个样本,提前 24 小时预测每小时。这是我目前正在尝试运行模型的地方
model8 = keras.models.Sequential([
keras.layers.LSTM(10, input_shape=(X_train.shape[1], X_train.shape[2]), return_sequences = True),
keras.layers.LSTM(20, return_sequences= True),
keras.layers.TimeDistributed(keras.layers.Dense(24))
])
model8.compile(loss="mape", optimizer="adam")
history = model8.fit(X_train, Y_train, epochs=2,
validation_data=(X_valid, Y_valid))
ValueError: Error when checking target: expected time_distributed_26 to have shape (168, 24) but got array with shape (24, 1)
任何帮助都将不胜感激,因为我不完全理解为什么时间分布层期望过去的所有 168 小时(有 24 个特征?),而不仅仅是对未来的预测。
【问题讨论】:
标签: tensorflow keras neural-network lstm recurrent-neural-network