0
votes

I'm new to keras and I want to build a deep RNN my x_train shape is (1115,106) and my y_train has (1115,11) samples, I can't fix the error I get from the code below:

    model_3=Sequential()

    model_3.add(LSTM(64,return_sequences=True,activation='relu'))
    model_3.add(Dropout(0.2))

    model_3.add(LSTM(64,activation='relu'))
    model_3.add(Dropout(0.2))

    model_3.add(Dense(64,activation='relu'))
    model_3.add(Dropout(0.2))

    model_3.add(Dense(11,activation='softmax'))


    model_3.compile(optimizer='adam',
          loss='mean_squared_error',
          metrics=['accuracy'])

    DNN_3= model_3.fit(x_train, y_train,batch_size=64, epochs=100)

in () 24 metrics=['accuracy']) 25 ---> 26 DNN_3= model_3.fit(x_train, y_train,batch_size=64, epochs=100) 27 28

ValueError: Input 0 is incompatible with layer lstm_24: expected ndim=3, found ndim=2

1

1 Answers

0
votes

You have to do two things:

  1. LSTM takes input of shape (n_samples, n_timesteps, n_features) and that's why it "expected ndim=3". So if you have 1000 data points over time (rounding 1115 for simplicity), then you can reshape your data into shape of (40, 25, 106) for input and (40, 25, 11) for output. Choices of n_samples and n_timesteps depends on the problem and should be decided by you. This will fix the error you are getting now, but then you would run into another error.

  2. Add return_sequences=True to the second LSTM as well as it seems you need a many-to-many architecture.