1
$\begingroup$

I'm making a CNN-LSTM model to forecast multivariate time series:

       model = Sequential()
       #model.build((10,7,1))
       model.add(Conv1D(filters=64,  kernel_size=2, activation='relu',input_shape=(10,7),strides=1))
       model.add(Conv1D(filters=128, kernel_size=2, activation='relu',strides=1))
       model.add(MaxPooling1D(pool_size=2))
       #model.add(Flatten())
       model.add(LSTM(200,return_sequences=True, activation='relu', recurrent_activation="sigmoid"))
       model.add(Dense(32, activation='sigmoid'))
       model.add(Dense(1))
       model.compile(optimizer='RMSprop', loss='mse',metrics=['accuracy'])
       model.summary()
       print('a new model has been created')

I have as input 7 features ("Time series") and a single output.

I made a function (make_samples to sample the data into sliding window size 10 in code called as n_steps

def make_samples(self,file, n_steps):
    X, y = list(), list()
    data=pd.read_csv(file)
    for i in range(len(data)):
        # find the end of this pattern
        end_ix = i + n_steps
        # check if we are beyond the dataset
        if end_ix > len(data):
            break
        # gather input and output parts of the pattern
        seq_x = data[self.lista].values[i:end_ix]
        seq_y = data["Volume"].values[end_ix-1]
        X.append(seq_x)
        y.append(seq_y)

    return array(X).astype("float32"),array(y).astype("float32")

When I pass this data to the model I got the following error:

Error when checking target: expected dense_30 to have 3 dimensions, but got array with shape (659, 1))

The question is, why does this error arise? And, how do I go about fixing this?

Here is the summary of


Layer (type) Output Shape Param

conv1d_38 (Conv1D) (None, 9, 64) 960


conv1d_39 (Conv1D) (None, 8, 128) 16512


max_pooling1d_18 (MaxPooling (None, 4, 128) 0


lstm_18 (LSTM) (None, 4, 200) 263200


dense_29 (Dense) (None, 4, 32) 6432


dense_30 (Dense) (None, 4, 1) 33

Many thanks in advance

$\endgroup$
  • 1
    $\begingroup$ Can you please show us a sample of the data after the make_sampels function. $\endgroup$ – JahKnows Jul 11 at 13:19

Your Answer

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

Browse other questions tagged or ask your own question.