maukwm / energy_prediction Goto Github PK
View Code? Open in Web Editor NEWProject for building energy prediction models with convolutional recurrent neural networks
Project for building energy prediction models with convolutional recurrent neural networks
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.