我有9000个序列,每个序列的长度为200,只有一个功能。
#data.shape= (9000,200,1)
我想基于长度为190的输入序列来预测长度为200的序列。
X是长度为190的输入序列,Y是长度为200的输出序列。
X = np.delete(data,slice(50,60),1) # shape of X = (9000,190,1)
Y = data.copy() # shape of Y = (9000,200,1)
我的问题基于教程Encoder-Decoder Model for Sequence-to-Sequence Prediction
以及现有的stackoverflow问题 seq2seq prediction for time series
# returns train, inference_encoder and inference_decoder models
def define_models(n_input, n_output, n_units):
# define training encoder
encoder_inputs = Input(shape=(None, n_input))
## First LSTM Layer (Encoder layer)
encoder = LSTM(n_units, return_state=True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
encoder_states = [state_h, state_c]
# define training decoder
decoder_inputs = Input(shape=(None, n_output))
## Second LSTM Layer (Decoder layer)
decoder_lstm = LSTM(n_units, return_sequences=True, return_state=True) # Decoder returns sequence, while encoder do not
decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state=encoder_states) # initial state of decoder is set to encoder states
## Dense Layer of decoder
decoder_dense = Dense(n_output, activation='softmax')
decoder_outputs = decoder_dense(decoder_outputs)
model = Model([encoder_inputs, decoder_inputs], decoder_outputs) # this is trained model containing both encoder and decoder
# define inference encoder
encoder_model = Model(encoder_inputs, encoder_states)
# define inference decoder
decoder_state_input_h = Input(shape=(n_units,))
decoder_state_input_c = Input(shape=(n_units,))
decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
decoder_outputs, state_h, state_c = decoder_lstm(decoder_inputs, initial_state=decoder_states_inputs)
decoder_states = [state_h, state_c]
decoder_outputs = decoder_dense(decoder_outputs)
decoder_model = Model([decoder_inputs] + decoder_states_inputs, [decoder_outputs] + decoder_states)
# return all models
return model, encoder_model, decoder_model
train, infenc, infdec = define_models(1, 1, 128)
train.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
在本教程中,作者使用两个输入序列来拟合模型,例如
train.fit([X1, X2], y, epochs=1)
我的问题是我该如何解决我的问题(当我只有一个功能时,如何创建数组X2(上下文向量))? X2是根据教程的目标输出的移位序列。