我正在使用LSTM进行单变量时间序列能源消耗预测。数据集每天有48个值,即每半小时取一个值,当我建立模型时,它只能对前一两个步骤进行更好的预测,然后变平为常数。我想预测下一个144次时间间隔的值。我的next_batch()函数具有以下代码。
def next_batch(training_data,batch_size,steps):
rand_start = np.random.randint(0,len(training_data)-steps)
y_batch = np.array(training_data[rand_start:rand_start+steps+1]).reshape(1,steps+1)
return y_batch[:, :-1].reshape(-1, steps, 1), y_batch[:, 1:].reshape(-1, steps, 1)
我想预测更长时间(即接下来的两三天)的值。建议更改代码。
num_inputs = 1
num_time_steps = 48
num_neurons = 100
num_outputs = 1
learning_rate = 0.02
num_train_iterations = 4000
batch_size = 48
with tf.Session() as sess:
saver.restore(sess, "./ex_time_series_model")
train_seed = list(train_scaled[-121:])
for iteration in range(121):
X_batch = np.array(train_seed[-num_time_steps:]).reshape(1, num_time_steps, 1)
y_pred = sess.run(outputs, feed_dict={X: X_batch})
train_seed.append(y_pred[0, -1, 0])