我的数据集中有以下3列: 1.month,2.day_of_week,3.quantity。
我想预测未来的数量值,有以下变量作为解释:
这种分析能否得到LSTM模型的支持?我相信我已经成功地创建了一个LSTM模型,它以两个延迟作为解释,但我不知道如何将19个外生因素(从两个热编码)作为解释变量添加到模型中。
注意:我正在使用Keras库来实现。
发布于 2021-08-11 02:27:15
RNN输入是三维张量,即
输入:具有形状批处理、时间步骤、特性的三维张量
最后两个延迟意味着您正在考虑timestamps=2。但是您应该尝试使用较长的序列并观察结果。
您可以将数据集创建为批次,1,20,即7+12+1 特性 for seq_len=1。
更长的时间。只需创建seq。因此,即我们为0,1,2,3 = [0,1,1,2,2,3]为seq_len=2创建通用时序数据的方式。
玩具代码-
mon = pd.get_dummies(np.random.randint(0,12,(1000)))
day = pd.get_dummies(np.random.randint(0,7,(1000)))
x = pd.DataFrame(np.random.randint(0,1000,(1000)))
data = pd.concat([x,mon,day], axis=1).to_numpy().reshape(-1,1,20)#seq_len=1, features=20
y = pd.get_dummies(np.random.randint(0,2,(1000)))
model = Sequential()
model.add(layers.GRU(100, return_sequences=True, input_shape=(1, 20)))
model.add(layers.GRU(100, return_sequences=False))
model.add(layers.Dense(1000, activation='relu'))
model.add(layers.Dense(2, activation='softmax'))
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy'])
history = model.fit(data, y, epochs=10)使用神经网络的Side_note - OHE可能不能给出最好的结果。尝试在月/日之前添加嵌入层。或者使用提供连续输出的其他编码。
https://datascience.stackexchange.com/questions/99883
复制相似问题