1

I'm trying to build a CNN-LSTM model for multivariate time series multi-step forecasting. The input is (2000 x 4) where 4 is the number of columns in my dataset. I got this error: ValueError: Shapes (None, 4) and (None, 1) are incompatible

this is the model:

input_shape = (window_size, 4)
model = Sequential([
    Conv1D(filters=8, kernel_size=1, activation='relu', input_shape=input_shape),
    Conv1D(filters=8, kernel_size=1, activation='relu', input_shape=input_shape),
    MaxPooling1D(pool_size=2),
    Bidirectional(LSTM(64, return_sequences=True)),
    Dropout(0.5),
    Bidirectional(LSTM(64)),
    Dense( 32, activation='relu'),
    Dense(1)
])

and where to fit the model

optimizer = tf.keras.optimizers.SGD(learning_rate=0.01)
model.compile(optimizer= optimizer,
              loss=tf.keras.losses.Huber(),
              metrics= [RootMeanSquaredError(), cc])
history = model.fit(
    X_train, y_train,
    epochs=50,
    batch_size=64,
    validation_data=(X_val, y_val),
    callbacks=[early_stopping])

How to solve this error please, where the output should be like this (test size * 4 * prediction_length)

  • Maybe `MaxPooling1D` [ref](https://keras.io/api/layers/pooling_layers/max_pooling1d/) is flattening the 4 columns into 1? `output_shape = (input_shape - pool_size + 1) / strides` – M.K Jul 04 '23 at 21:05

0 Answers0