所以我想使一个lstm网络运行在我的数据上,但是我收到此消息:
ValueError:检查输入时出错:预期lstm_1_input的形状为(None,1),但数组的形状为(1,557)
这是我的代码:
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)
最佳答案
您需要更改input_shape
层的LSTM
值。另外,x_train
必须具有以下shape
。
x_train = x_train.reshape(len(x_train), x_train.shape[1], 1)
所以,改变
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]) )))
至
x_train = x_train.reshape(len(x_train), x_train.shape[1], 1)
model.add(LSTM(50, input_shape=(x_train.shape[1], 1) )))
关于python - keras lstm错误:预期会看到1个数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60054101/