2

I have a question about using LSTM model to predict sales. To build the model, I want to input the previous sales values(choose sample size of 30), and also the current(t) features such as whether on promotion, whether is a holiday etc. My current code:

def create_dataset(dataset, look_back=1):
dataX, dataY = [], []
for i in range(len(dataset)-look_back-1):
    a = dataset[i:(i+look_back), 0]
    dataX.append(a)
    dataY.append(dataset[i + look_back, 0])
return np.array(dataX), np.array(dataY)

look_back = 30
trainX, trainY = create_dataset(train, look_back)
valX, valY = create_dataset(val, look_back)

# note: train and val dataset here only include sale values

trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
valX = np.reshape(valX, (valX.shape[0], 1, valX.shape[1]))

Which I create n*30 datasets(30 columns). And then I apply into the keras LSTM model. But how can I also include the current features (not time sequence) as input into the model?

Icy
  • 31
  • 1
  • 3

1 Answers1

2

If you build your model in a nonsequential way, with the functional API you can have multiple inputs. You could then process your timesequence with lstm and process the input with the current featuers in some dense layers. Then you merge them and use some more dense layers as example before making your predictions.

Some examples can be found under https://keras.io/getting-started/functional-api-guide/

Syrius
  • 941
  • 6
  • 22