我有一个每小时污染量(‘Sample_Measurement)和天气状况的数据集。如果我想用前n小时的天气和污染数据来预测当前小时的污染水平,我没有问题。事实上,假设n= 24,特征数为5。三维矢量将具有如下形状(元素数,24,5)。

在此之前,我没有问题,但我想要做的是使用当前小时的天气条件(以及前一个24小时),因为在前一个例子中,我只使用了前n个小时的数据。问题是,我不知道该如何做,因为3D矢量作为三维5 (4个天气特征加上1个表示污染程度的特征),所以我不能简单地添加当前的小时天气特征,因为特征(4 )的数量是不同的(因为对于当前的时间,我们没有当前的污染,也就是我们想要预测的污染)。我希望我已经弄清楚了,但解释起来并不容易。
发布于 2019-07-05 13:26:13
您可以尝试执行以下操作(前面的伪代码):
input_past_24 = Input(shape=(24,5))
input_today = Input(shape(1,4))
output_from_LSTM = LSTM(some_args, ...)(input_past_24) # this has some size of your choice, let's say N
# if you want to add other layers, you'd do it here.
prediction = Dense(some_args, ...)(concatenate(input_today,output_from_LSTM))
model = Model(inputs=[input_past_24,input_today], output=prediction)
model.compile(some_args)
model.fit([data_from_past_days,data_today],expected_pollution, some_other_args...)上面,关键是将LSTM层的输出与当天的输入连接起来,然后将其发送到最终的Dense层进行最终预测。
关于更多的细节,您可能需要检查Keras的函数式API指南。
https://datascience.stackexchange.com/questions/37212
复制相似问题