Я пытаюсь предсказать траекторию объекта в 3 измерениях на несколько шагов в будущее, учитывая временной ряд измерений. Я начинаю с проблемы с игрушкой, показанной ниже, с тремя последовательностями. Моя цель - получить серию прогнозов от 1 до n_steps_out для каждой координаты. Тем не менее, я не могу настроить плотный слой вывода, и я думаю, что я что-то упустил концептуально.
В этом игрушечном примере я получаю в общей сложности 5 примеров, 2 шага прогнозирования с 3 функциями и получаю ошибку значения
«ValueError: Ошибка при проверке цели: ожидалось, что плотность_1 имеет 2 измерения, но получен массив с формой (5, 2, 3)»
Заранее спасибо за любые рекомендации, которые вы можете дать мне
'' '
# multivariate multi-step stacked lstm example
from numpy import array
from numpy import hstack
from keras.models import Sequential
from keras.layers import LSTM
from keras.layers import Dense
# split a multivariate sequence into samples
def split_sequences(sequences, n_steps_in, n_steps_out):
X, y = list(), list()
for i in range(len(sequences)):
# find the end of this pattern
end_ix = i + n_steps_in
out_end_ix = end_ix + n_steps_out
# check if we are beyond the dataset
if out_end_ix > len(sequences):
break
# gather input and output parts of the pattern
seq_x, seq_y = sequences[i:end_ix, :], sequences[end_ix:out_end_ix,:]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
# define input sequence training data
in_seq1 = array([1, 2, 3, 4, 5, 6, 7, 8, 9])
in_seq2 = array([2, 4, 6, 8, 10, 12, 14, 16, 18])
in_seq3 = array([3, 6, 9, 12, 15, 18, 21, 24, 27])
# convert to [rows, columns] structure
in_seq1 = in_seq1.reshape((len(in_seq1), 1))
in_seq2 = in_seq2.reshape((len(in_seq2), 1))
in_seq3 = in_seq3.reshape((len(in_seq3), 1))
# horizontally stack columns
dataset = hstack((in_seq1, in_seq2, in_seq3))
# choose a number of time steps
n_steps_in, n_steps_out = 3, 2
# covert into input/output
X, y = split_sequences(dataset, n_steps_in, n_steps_out)
# the dataset knows the number of features, e.g. 2
print(X.shape, y.shape)
# summarize the data
for i in range(len(X)):
print(X[i], y[i])
n_features = X.shape[2]
# define model
model = Sequential()
model.add(LSTM(100, activation='relu', return_sequences=True, input_shape=(n_steps_in, n_features)))
model.add(LSTM(100, activation='relu'))
model.add(Dense(n_steps_out))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=10, verbose=1)
# demonstrate prediction
x_input = array([[10, 20, 30], [11, 22, 33 ], [12, 24, 36]])
x_input = x_input.reshape((1, n_steps_in, n_features))
yhat = model.predict(x_input, verbose=0)
print(yhat)
'' '