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:
JavaScript
x
12
12
1
x_train=numpy.array(x_train)
2
x_test=numpy.array(x_test)
3
x_train = numpy.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
4
x_test = numpy.reshape(x_test, (x_test.shape[0], 1, x_test.shape[1]))
5
# create and fit the LSTM network
6
model = Sequential()
7
model.add(LSTM(50, input_shape=(1,len(x_train[0]) )))
8
model.add(Dense(1))
9
model.add(Dropout(0.2))
10
model.compile(loss='mean_squared_error', optimizer='adam')
11
model.fit(x_train, numpy.array(y_train), epochs=100, batch_size=1, verbose=2)
12
Advertisement
Answer
You need to change the input_shape
value for LSTM
layer. Also, x_train
must have the following shape
.
JavaScript
1
2
1
x_train = x_train.reshape(len(x_train), x_train.shape[1], 1)
2
So, change
JavaScript
1
3
1
x_train = numpy.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
2
model.add(LSTM(50, input_shape=(1,len(x_train[0]) )))
3
to
JavaScript
1
3
1
x_train = x_train.reshape(len(x_train), x_train.shape[1], 1)
2
model.add(LSTM(50, input_shape=(x_train.shape[1], 1) )))
3