Reputation: 362
I'm making a prediction over daily sales data for a company using Keras LSTM. The original shape of the data is [60 shops x 1034 days x 207 products]. I have created One-hot representation of days like:
This rep is added to the date of all shops so the shape new shape is [60 shops x 1034 days x (207 products + 7 days)]
I have added one more column named S_day for days of great significance with value either 0 or 1.
So the final dimension of data is [60 x 1034 x 215].
I use for train the upper 973 days and for test the last 61 days of the set for everyshop.
train_x [60 x 973 x 215]
train_y [60 x 973 x 215]
test_x [60 x 973 x 215] (data shape is [60 x 61 x 215] but we pad zeros to match shape)
test_y [60 x 973 x 215](data shape is [60 x 61 x 215] but we pad zeros to match shape)
y data are x data shifted with lag -1 in order to have as target of prediction the next day.
My problem is that I need to exclude those 8 extra columns from my final prediction.
# design model
model = Sequential()
model.add(LSTM(100, input_shape=(train_x.shape[1], train_x.shape[2]), return_sequences=True))
model.add(Dense(train_x.shape[2]))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
# fit model
history = model.fit(train_x, train_y,
epochs=10,
batch_size=2,
validation_data=(test_x, test_y),
verbose=2,
shuffle=False)
# make a prediction
test_pred = model.predict(test_x)
Upvotes: 1
Views: 1710
Reputation: 362
I found the way to solve it I only had to reshape drop 8 columns from train_y and train_x in order to have 207 features and have in Dense layer input 207
Upvotes: 0
Reputation: 23
I think you have made a mistake in your dimensions. It should be (60 x 1034 x 7 x 207 x 1) So the network has a 4 dim input and you flatten before passing to dense layer and taking output. If you could post an image of your code to take the data, it can be made a bit more clear.
The output can be converted into whatever you want using a one_hot_decoder()
Upvotes: 0