Issue
I read this article about LSTM:
https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/
The first basic example is about "Vanilla LSTM": predict next time series
Where the input = [10, 20, 30, 40, 50, 60, 70, 80, 90]
In the article the writer split the input (sequence) into matrix:
X, y
10, 20, 30 40
20, 30, 40 50
30, 40, 50 60
...
I can't understand why the input need to reshape:
reshape from [samples, timesteps] into [samples, timesteps, features]
1. Why do we need this ?
In addition if my input is like (the basic example + ID columns):
ID X, y
1 10, 20, 30 40
1 20, 30, 40 50
2 30, 40, 50 60
2 40, 50, 60, 70
...
2. how we reshapes it ? what we will be the new dimensional ?
Solution
I think this link will help you understand why.
You always have to give a three-dimensional array as an input to your LSTM network. Where the first dimension represents the batch size, the second dimension represents the number of time-steps you are feeding a sequence. And the third dimension represents the number of units in one input sequence. For example, input shape looks like (batch_size, time_steps, seq_len)
Lets take your example sequence: [10, 20, 30, 40, 50, 60, 70, 80, 90]
Once we do split_sequence as stated in your article, we get a 2 dimensional feature vector X of shape (6, 3). Where 6 is number of samples and 3 is number of steps.
but given that the model only takes in a 3-D vector we must reshape our 2-d vector to 3-d.
so from (6, 3) --> (6, 3, 1).
To answer your second question, you can simply reshape your 2-d feature vector X by doing the following:
# Given that X is a numpy array
samples = X.shape[0]
steps = X.shape[1]
X = X.reshape(samples, steps, 1)
Answered By - Aakash Dusane
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.