EmJ
EmJ

Reputation: 4608

How to make lstm model for sequence prediction

I have signals recorded from machines in every minute for 6 hours. i.e. the length of the signal of a machine is 6*60 = 360. My clients have recorded these signals for each machine for a month. In other words, each machine has 360 length signals for 28 days. I have the data of about 2000 machines in my dataset.

If you want to get the idea of how my dataset looks like, I have mentioned a quick overview of it below (Note: each signal in each day is 360 length long as described in the question).

machine_num, day1, day2, ..., day28
m1, [12, 10, 5, 6, ...], [78, 85, 32, 12, ...], ..., [12, 12, 12, 12, ...]
m2, [2, 0, 5, 6, ...], [8, 5, 32, 12, ...], ..., [1, 1, 12, 12, ...]
...
m2000, [1, 1, 5, 6, ...], [79, 86, 3, 1, ...], ..., [1, 1, 12, 12, ...]

My client expects a model that predicts the signal sequence of each machine for next 3 days. i.e. in day29, day30, day31. In other words, the model should learn the sequences from day1 to day29 and predict the next three sequences.

So, I started searching deep learning models and found the model Seq2Seq that seems to suit my problem.

My current code is as follows.

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, RepeatVector, Dense, TimeDistributed
from tensorflow.keras.activations import elu  
hidden_size = 50
seq2seq = Sequential([
    LSTM(hidden_size, input_shape = (input_sequence_length, no_vars)),
    RepeatVector(prediction_length), 
    LSTM(hidden_size, return_sequences = True), 
    Dense(hidden_size, activation = elu)
    TimeDistributed(Dense(1, activation = elu))
])

However, due to my limited knowledge in deep learning I am not sure what I am doing is correct. Moreover, I do not have data for day_29, day_30 and day_31. So, I am also wondering how to do the training part? I am so stucked in this problem as I do not have a clear mind how to proceed.

I am happy to provide more details if needed.

EDIT:

It looks like LSTM is the potential model for my problem since I do not have training data for day_29, day_30 and day_31. I am wondering whether the process of @ESDARII is a buit-in function in LSTM or do we have to write it from scratch in keras. Please let me know your thoughts and if you have any other suggestions.

Upvotes: 0

Views: 739

Answers (1)

ESDAIRIM
ESDAIRIM

Reputation: 651

your network shouldn't really be a seq2seq network.

What I suggest is using a simple RNN or LSTM, that works as follows:

it gets all signals for days from 1 to J-1 and predicts the signal for the Jth day, for example:

if the first step, it gets signals for day 1 and asked to predict signals for day 2, then in the next step get signals for days 1, 2 and asked to predict signals for day 3, etc, so when you reach day 28, the network has all the signals up to 28 and is asked to predict the signals for day 29, etc.

this way you can overcome the fact that you don't have values for days 29, 30 and 31. because your network will be very good at predicting the signals for day J, given signals for days up to J-1.

Upvotes: 2

Related Questions