Мой код модели LSTM без стека Tensorflow хорошо подходит для этого: [code]# reshape input to be [samples, time steps, features] trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1])) testX = np.reshape(testX, (testX.shape[0], 1, testX.shape[1]))
# create and fit the LSTM network model = Sequential() model.add(LSTM(4, input_shape=(1, LOOK_BACK)))
# make predictions trainPredict = model.predict(trainX) testPredict = model.predict(testX) [/code] Если я попытаюсь последовательно добавить больше слоев с помощью этого: [code]# create and fit the LSTM network model = Sequential() batch_size = 1 model.add(LSTM(4, batch_input_shape=(batch_size, LOOK_BACK, 1), stateful=True, return_sequences=True)) model.add(LSTM(4, batch_input_shape=(batch_size, LOOK_BACK, 1), stateful=True)) [/code] Это приведет к ошибке: [code]ValueError: Input 0 of layer "lstm_6" is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 4) [/code] Вот похожая запись SO.