How to model the data for sequence to sequence prediction with only one feature

左心房为你撑大大i 提交于 2020-02-07 05:22:16

问题


I have 9000 sequences each of length 200, only one feature.

#data.shape= (9000,200,1)

I want to predict the sequence of length 200 based on input sequence of length 190. X is input sequence of length 190, and Y is output sequence of length 200.

X = np.delete(data,slice(50,60),1)  # shape of X = (9000,190,1)
Y = data.copy() # shape of Y = (9000,200,1)

My question is based on the tutorial Encoder-Decoder Model for Sequence-to-Sequence Prediction

and on existing stackoverflow question 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'])

In the tutorial author fit the model using two input sequences like

train.fit([X1, X2], y, epochs=1)

My question is how do I fit my problem this way (How to create array X2 (Context vector), when I only have one feature)? X2 is shifted sequence of target output according to tutorial.

来源:https://stackoverflow.com/questions/58491120/how-to-model-the-data-for-sequence-to-sequence-prediction-with-only-one-feature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!