# How to create a Time Series Training Dataset with variable sequence length

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.

• What would be the needed dataset in your example ? – manu190466 Apr 21 at 17:28

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()

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.