Home > Software design >  CNN model for timeseries prediction
CNN model for timeseries prediction

Time:11-25

I want to build a CNN model. I have x_train=8000000x7, y_train=8000000x2. Since it is a multivariant time series. How can feed the input with window size of 160 and stride=1.

what should be the input for cnn model?

I used timeseriesgenerator for creating a dataset as follows

train_gen = tf.keras.preprocessing.sequence.TimeseriesGenerator(X_train, Y_train,
                                                                length=160, sampling_rate=1,shuffle=False, batch_size=256)


batch_0  = train_gen[0]
data, label = batch_0
print("Shape of the generator data and label:", data.shape, label.shape)

input=data.shape[1],data.shape[2]

For LSTM I have used 'input' as the input shape. What should be the input for CNN model.

1)can use timeseriesgeneartor for CNN model? 2) is there any datagenerator for creating a sliding window approach?

CodePudding user response:

First, TimeseriesGenerator is deprecated and do not take tensorflow tensor as input so I discourage to use it. Instead you can use timeseries_dataset_from_array (doc here) from keras utils. It also generate sliding windows.

For time serie prediction, you should use 1-D CNN. They take a sequence as input exactly like LSTM. As shape is concerned, in Tensorflow it is still:

input = data.shape[1], data.shape[2]

Assuming that data.shape[0] is the batch size, data.shape[1] the sequence length and data.shape[2] the number of features of each elements.

  • Related