1
$\begingroup$

I have time series data with variable sequence lengths. So something like:

date        value label
2020-01-01  2     0     # first input time series
2020-01-02  1     0     # first input time series
2020-01-03  1     0     # first input time series
2020-01-01  3     1     # second input time series
2020-01-03  1     1     # second input time series

how is it possible to create a training dataset (numpy arrays) of shape [samples, time_steps, n_features] when time_steps is not consistent?

Additional Info: The model that is going to be trained is an LSTM which is capable to handle variable input lengths.

$\endgroup$
  • $\begingroup$ What would be the needed dataset in your example ? $\endgroup$ – manu190466 Apr 21 at 17:28
1
$\begingroup$

I solved it the following way:

  1. zero padding all time series that are smaller than the longest one
  2. adding a Masking()layer with masking_value=0. which ignores all zero values before feeding the network.

The part of the model with the Masking layer looks like the following:

model = keras.Sequential()
model.add(layers.Masking(mask_value=0., input_shape=(None, 1)))
model.add(layers.LSTM(100))

Additional Info: Implementing the Masking Layer for a Model with two separate Inputs was kind of unconvinient with a the Keras Functional API, therefore i implemented that part of the model with the Keras Sequential API and connected it to the rest of the model which is implemented with the Functional API.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.