Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

keras - Passing data to RNN with Sliding window approach

I having hard time with LSTM's and RNN so my apologies if this question sounds like a very basic question. I would appreciate if you can help in any way. I am trying to train my RNN with LSTMs, but I am not sure on how to setup my model and data pipeline.

My data looks like below. It has 2 features for the input and I am predicting single label from multiple classes

Input =

array([[A, 0.250],
       [B, 0.654],
       [C, 0.643],
       [D, 0.859],
       [E, 0.135],
       [F, 0.913],
       [G, 0.493],
       [H, 0.267]])

Output =

array([[2],
       [3],
       [4],
       [4],
       [0],
       [1],
       [1],
       [2]])

I do have many samples for my data. For sake of simplicity here let's say I have 100 sample. So my input and output shapes are like this input_shape(100,8,2) output_shape=(100,8,1) I hope its clear that my RNN time steps are 8.

Now based on this https://datascience.stackexchange.com/questions/27628/sliding-window-leads-to-overfitting-in-lstm, I have concluded that I need a sliding window approach to split my data so that it can learn all the relatioship between different time steps, since that's the key for my data. Let's say my sliding window is 6 then my shapes become like this input_shape(100,4,8,2) and output_shape(100,4,8,1)

  1. How do I split my input and output data in a way to get the sliding window of 6 and in a way that I get the above shape ?

Now I have RNN defined like like this

model = Sequential()   
model.add(Bidirectional(LSTM(units=128), , return_sequences=True, input_shape=(8,2))
model.add(Dense(8, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  1. How will pass my input and outputs to my RNN ?
question from:https://stackoverflow.com/questions/66050399/passing-data-to-rnn-with-sliding-window-approach

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...