I\'m trying to use LSTM to do store sales forecast. Here is how my raw data look like:
| Date | StoreID | Sales | Temperature | Open | StoreType |
|
I was recently solving similiar problem. In your case:
Input should have shape (300, 20, 1)
- because you have time sequences of length 20
with 1
feature.
You may do it like this:
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)
This is the hardest part. I do not advise you to predict multiple shops by feeding them to a network as one feature vector. You may under simply skip this part and try to predict different shops using one model or postprocess output using e.g. some kind of graphical models or PCA
on matrix where rows are day sales.
UPDATE:
In order to deal with multiple sequential features you could do the following thing:
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])
In this case your input should consist of list of two tables: [sequential_data, features]
where sequential_data.shape = (nb_of_examples, timesteps, sequential_features)
and features.shape = (nb_of_examples, feature_nb)
. So sales
or temperature
should be stored in sequential_features
and store_type
in features
.