1

so i want to make a lstm network to run on my data but i get this message:

ValueError: Error when checking input: expected lstm_1_input to have shape (None, 1) but got array with shape (1, 557)

this is my code:

x_train=numpy.array(x_train)
x_test=numpy.array(x_test)
x_train = numpy.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
x_test = numpy.reshape(x_test, (x_test.shape[0], 1, x_test.shape[1]))
# create and fit the LSTM network
model = Sequential()
model.add(LSTM(50, input_shape=(1,len(x_train[0]) )))
model.add(Dense(1))
model.add(Dropout(0.2))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, numpy.array(y_train), epochs=100, batch_size=1, verbose=2)

1 Answer 1

2

You need to change the input_shape value for LSTM layer. Also, x_train must have the following shape.

x_train = x_train.reshape(len(x_train), x_train.shape[1], 1)

So, change

x_train = numpy.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
model.add(LSTM(50, input_shape=(1,len(x_train[0]) )))

to

x_train = x_train.reshape(len(x_train), x_train.shape[1], 1)
model.add(LSTM(50, input_shape=(x_train.shape[1], 1) )))
Sign up to request clarification or add additional context in comments.

1 Comment

thank you but now i am getting this error: ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (7352, 557)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.