0

I want to do predictions with a LSTM model, but the dataset isn't a single file, it's composed with multiple files (for example 3 Excels).

I've already checked that if you want to deal with a time series forecasting problem you have to prepare your data like (number of samples, number of time steps, number of features) and it works well if I implement this for a single Excel.

The problem consists in training with the three Excels at the same time, in this case the input tensor for the LSTM layer has the shape: (n_files, n_samples, n_timesteps, n_features), with dim = 4. This doesn't work because LSTM layers only admits input tensors with dim = 3.

My files have the same amount of data. It's collected from a device and the data has 1 value for each minute along the duration of the experiment. All the experiments have the same duration too.

I've tried to concatenate the files in order to have 1, and choosing the batch_size as the number of samples in one Excel (because I can't mix the different experiments) but it doesn't produce a good result (at least as good as the results from predicting with 1 experiment).

def build_model():
  model = keras.Sequential([
    layers.Masking(mask_value = 0.0, input_shape=[1,1]),
    layers.LSTM(50, return_sequences=True),
    layers.Dense(1)
  ])

  optimizer = tf.keras.optimizers.Adam(0.001)

  model.compile(loss='mse',
                optimizer=optimizer,
                metrics=['mae','RootMeanSquaredError'])
  return model

model_pred = build_model()
model_pred.fit(Xchopped_train, ychopped_train, batch_size = 252,
               epochs=500, verbose=1)

Where Xchopped_train and ychopped_train are the concatenated data from the 3 Excel.

Another thing I've tried is to train the model within a loop, and changing the Excel:

for i in range(len(Xtrain)):
    model_pred.fit(Xtrain[i], Ytrain[i], epochs=167, verbose=1)

Where Xtrain is (3,252,1,1) and the first index refers to the number of Excel.

And by far this is my best approach but it feels like this isn't a good solution since I don't know what's happening with the NN weights or which loss function is minimizing...

Is there a more efficient way to do this? Thanks!

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Duktti
  • 1

0 Answers0