Giter Club home page Giter Club logo

energy_prediction's People

Contributors

maukwm avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jiweizh

energy_prediction's Issues

time series prediction

Hi, I am currently doing a similar time series forecasting for numbers of calls with seq2seq model. Now I meet a problem which is that when I want to predict like 30 days target's values in the future, the results will not perform any trend of series.

The code of the model is like this:

# train model
latent_dim = 128 # LSTM hidden units
dropout = .20 

encoder_inputs = Input(shape=(None, n_inputs), name='encoder_inputs') 

encoder_lstm = LSTM(latent_dim, dropout=dropout, return_sequences=False, return_state=True, name='encoder_lstm')

_, state_h, state_c = encoder_lstm(encoder_inputs)

encoder_states = [state_h, state_c]


decoder_inputs = Input(shape=(None, n_features), name='decoder_inputs') 


decoder_lstm = LSTM(latent_dim, dropout=dropout, return_sequences=True, return_state=True, name='decoder_lstm')
decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state=encoder_states)

decoder_dense = (Dense(n_outputs, name='decoder_dense', activation='linear')) 
decoder_outputs = decoder_dense(decoder_outputs)

model = Model([encoder_inputs, decoder_inputs], decoder_outputs)

model.compile(COCOB(), loss=ks.losses.mean_squared_error)

history = model.fit([encoder_input_data, decoder_input_data], decoder_target_data,
                     batch_size=16,  epochs=100,
                     validation_split=0.2, shuffle=False)

# define inference encoder
encoder_model = Model(encoder_inputs, encoder_states)

decoder_state_input_h = Input(shape=(latent_dim,))
decoder_state_input_c = Input(shape=(latent_dim,))
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)
# decoded sequence 
n_test_samples = encoder_input_data_test.shape[0]
print('Total number of test smaples:', n_test_samples)

n_seq_out = 1  #length of days for predicting, objective is to predict 3 months in the future
all_out = []

for i in range(n_test_samples):
    enc_outs = encoder_model.predict(encoder_input_data_test[i:i+1,:,:])
    
    target_seq = np.zeros((1,1,n_features))
    
    target_seq[0,:,:] = encoder_input_data_test[i,-1:,:]
    
    decoded_seq = np.zeros((1,n_seq_out,n_outputs))

    for j in range(n_seq_out):
        output, h, c = decoder_model.predict([target_seq]+enc_outs)
        print('out', output)
        print('tar', target_seq)
        decoded_seq[0,j,0] = output[0,0,0] 
        
        target_seq = np.zeros((1,1,n_features))
        target_seq[0,0,0] = output[0,0,0]
        target_seq[0,0,1:] = decoder_input_data_test[j+1,0,1:]
        enc_outs = [h, c]  
        
    all_out.append(decoded_seq)

My data input of encoder has the size (n_samples, steps=84 days, n_features), and the data of decoder input has the size(n_samples, steps=1 days, n_features) and the size of target data of decoder is (n_sample, steps=1, 1). Each sample of input data of encoder has one-day lag, and decoder input data is for realizing the teacher forcing.

Like if I just predict one day after, the predicted value is acceptable but not very precise. However, when I predict like 30 days after, the values of the predicted series will only increase or decrease unstoppable. Do you have any suggestion on this?

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.