Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在TensorFlow中使用lstm进行时间序列预测,而我的结果可能非常糟糕和荒谬_Python_Tensorflow_Lstm - Fatal编程技术网

Python 在TensorFlow中使用lstm进行时间序列预测,而我的结果可能非常糟糕和荒谬

Python 在TensorFlow中使用lstm进行时间序列预测,而我的结果可能非常糟糕和荒谬,python,tensorflow,lstm,Python,Tensorflow,Lstm,我在一组中有大约20个GDP,我想用TensorFlow中的LSTM NN预测未来10年的GDP表现。 正如原始数据所示,GDP应该呈指数增长,但我通过lstm得出的结果表明了完全相反的趋势,我发现调试非常混乱!!我的网络架构有什么问题吗 我尝试将学习率从0.1调整到0.0001,并更改了批次大小、时间步长和运行单位大小,两者都在(2,20)范围内,但这些方法都不起作用 原始数据: 年度国内生产总值 1996 349600 1997 422100 1998 479100 199

我在一组中有大约20个GDP,我想用TensorFlow中的LSTM NN预测未来10年的GDP表现。 正如原始数据所示,GDP应该呈指数增长,但我通过lstm得出的结果表明了完全相反的趋势,我发现调试非常混乱!!我的网络架构有什么问题吗

我尝试将学习率从0.1调整到0.0001,并更改了批次大小、时间步长和运行单位大小,两者都在(2,20)范围内,但这些方法都不起作用

原始数据:
年度国内生产总值
1996    349600
1997    422100
1998    479100
1999    389711
2000    428654
2001    486430
2002    565532
2003    677583
2004    950951
2005    1453209
2006    1831073
2007    2454598
2008    3018032
2009    4594015
2010    5736350
2011    7678600
2012    8793200
2013    10017593
2014    11153849
2015    11933430
2016    12933462
获取成批的培训数据:

def获取列车数据(标准化):
目标=列表()
标签=列表()
对于范围内的i(len(a\u np)-时间步长-1):
追加(标准化的[i:i+时间步])
label.append(标准化的[i+1:i+time\u step+1])
返回目标、标签
LSTM的基本信息:

time_step = 4
rnn_unit = 20
batch_size = 5
input_size = 1
output_size = 1
lr = 0.008
X = tf.placeholder(tf.float32, [None, time_step, input_size])
Y = tf.placeholder(tf.float32, [None, time_step, output_size])
weights = {
        'in': tf.Variable(tf.random_normal([input_size, rnn_unit])),
        'out': tf.Variable(tf.random_normal([rnn_unit, 1]))
    }
biases = {
    'in': tf.Variable(tf.constant(0.1, shape=[rnn_unit, ])),
    'out': tf.Variable(tf.constant(0.1, shape=[1, ]))
}
3层lstm从输入隐藏层到lstm最终到输出隐藏层:

def lstm(batch):
    w_in = weights['in']
    b_in = biases['in']
    input = tf.reshape(X, [-1, input_size])
    input_rnn = tf.matmul(input, w_in) + b_in
    input_rnn = tf.reshape(input_rnn, [-1, time_step, rnn_unit])
    cell = tf.nn.rnn_cell.BasicLSTMCell(rnn_unit, forget_bias=0.2, state_is_tuple=True)
    init_state = cell.zero_state(batch, dtype=tf.float32)
    output_rnn, final_states = tf.nn.dynamic_rnn(cell, input_rnn, initial_state=init_state, dtype=tf.float32)
    output = tf.reshape(output_rnn, [-1, rnn_unit])
    w_out = weights['out']
    b_out = biases['out']
    pred = tf.matmul(output, w_out) + b_out
    return pred, final_states
损失函数和优化器:

loss=tf.reduce_-mean(tf.square(tf.reformate(Y,[-1])-tf.reformate(pred,[-1]))
列op=tf.列AdamOptimizer(lr).最小化(损失)
这是预测结果
2017    [11262389.]
2018    [11572339.]
2019    [11730970.]
2020    [11825313.]
2021    [11873324.]
2022    [11906612.]
2023    [11924690.]
2024    [11935304.]
2025    [11941413.]

Hi,您的问题现在解决了吗。否则,我尝试复制错误,得到错误“NameError:name'pred'未定义”。你能分享完整的代码吗?这样我们就可以解决它了。谢谢