作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 LSTM 进行商店销售预测。这是我的原始数据的样子:
| Date | StoreID | Sales | Temperature | Open | StoreType |
|------------|---------|-------|-------------|---------|-----------|
| 01/01/2016 | 1 | 0 | 36 | 0 | 1 |
| 01/02/2016 | 1 | 10100 | 42 | 1 | 1 |
| ...
| 12/31/2016 | 1 | 14300 | 39 | 1 | 1 |
| 01/01/2016 | 2 | 25000 | 46 | 1 | 3 |
| 01/02/2016 | 2 | 23700 | 43 | 1 | 3 |
| ...
| 12/31/2016 | 2 | 20600 | 37 | 1 | 3 |
| ...
| 12/31/2016 | 10 | 19800 | 52 | 1 | 2 |
Window = 20
Horizon = 10
| trainX | trainY |
| [Yt-10, Yt-11, Yt-12,...,Yt-29] | [Yt, Yt-1, Yt-2,...,Yt-9] |
| [Yt-11, Yt-12, Yt-13,...,Yt-30] | [Yt-2, Yt-3, Yt-4,...,Yt-10] |
| [Yt-12, Yt-13, Yt-14,...,Yt-31] | [Yt-3, Yt-4, Yt-5,...,Yt-11] |
...
trainX.shape
(300, 1, 20)
trainY.shape
(300, 10)
最佳答案
我最近正在解决类似的问题。在你的情况下:
(300, 20, 1)
- 因为你有长度为 20
的时间序列与 1
特征。 sequential_input = Input(shape=(20, 1))
feature_input = Input(shape=(feature_nb,))
lstm_layer = LSTM(lstm_units_1st_layer, return_sequences=True)(sequential_input)
lstm_layer = LSTM(lstm_units_2nd_layer, return_sequences=True)(lstm_layer)
...
lstm_layer = LSTM(lstm_units_nth_layer, return_sequences=False)(lstm_layer)
merged = merge([lstm_layer, feature_input], mode='concat')
blend = Dense(blending_units_1st_layer, activation='relu')(merged)
blend = Dense(blending_units_2nd_layer, activation='relu')(blend)
...
output = Dense(10)(blend)
PCA
在行是日销售额的矩阵上。 sequential_input = Input(shape=(20, nb_of_sequental_features))
feature_input = Input(shape=(feature_nb,))
lstm_layer = LSTM(lstm_units_1st_layer, return_sequences=True)(sequential_input)
lstm_layer = LSTM(lstm_units_2nd_layer, return_sequences=True)(lstm_layer)
...
lstm_layer = LSTM(lstm_units_nth_layer, return_sequences=False)(lstm_layer)
merged = merge([lstm_layer, feature_input], mode='concat')
blend = Dense(blending_units_1st_layer, activation='relu')(merged)
blend = Dense(blending_units_2nd_layer, activation='relu')(blend)
...
output = Dense(10)(blend)
model = Model(input=[sequential_input, feature_input], output=output])
[sequential_data, features]
在哪里
sequential_data.shape = (nb_of_examples, timesteps, sequential_features)
和
features.shape = (nb_of_examples, feature_nb)
.所以
sales
或
temperature
应存储在
sequential_features
和
store_type
在
features
.
关于neural-network - 如何为具有外部特征的时间序列多步范围构建 LSTM 的输入数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42585356/
我是一名优秀的程序员,十分优秀!