TDo
TDo

Reputation: 744

Stateful vs Stateless LSTM

I am trying to use LSTM in Keras and I am not sure whether I should used statefull or stateless LSTM. I have read many resources online but seem like they do not apply to my case.

I have a long predictor series X=[X1,X2,....,Xn] and a long response series y=[0,0,...,1,1,0,...0]. They have the same length and the response can only take value 1 or 0. My plan is to subsample the long predictor series and use the short series (length 4) to predict the response for the next 3 time points. So my training data look look this

[X1,X2,X3,X4],[y5,y6,y7]
[X2,X3,X4,X5],[y6,y7,y8]
...

If I use all these short series (samples) available, I think I should choose stateful. However, because there are a lot more 0 in y compared to 1, I will keep all the samples that has 1 in the short response series (ex: keep this sample [y5=0,y6=1,y7=0]) but I will randomly drop a lot of other samples just to make the data balance.

I am not sure whether I should use stateful here, since some short series may be very far away from each other.

Upvotes: 0

Views: 273

Answers (1)

Ronakrit W.
Ronakrit W.

Reputation: 693

I believe you are trying to train a model using LSTM but you also want to remove some part of that time series data and be able to train the model at the same time.

Technically, you can achieve that simply just using stateful LSTM and chop your data into a same length then provide a sample_weight. For example, model.fit(x=data, y=class, sample_weight=np.array([1,1,0,0,0,1])), this will help you achieve what you want by removing index 2,3,4 without removing it from your data manually.

Normally, we modify loss instead of removing some part of time series out, something like wrongly classify class 1 will create 10 times loss than class 0.

Hope this help

Upvotes: 1

Related Questions