直接多步预测策略中增加预测步骤会使预测图变平,而不是变化

时间:2018-04-08 18:12:29

标签: machine-learning keras time-series

我正在用神经网络进行时间序列预测。只要我使用预测步骤= 0来提供网络(对于Y从参考日获取值),它看起来没问题。将预测步长增加N(对于Y从参考日+ N取值)会使预测图变平,如果将其移动N.任何想法可能出错?

修改

至于型号:

model = Sequential()
model.add(Dense(14, input_dim=14, kernel_initializer='normal', activation='relu'))
model.add(Dense(7, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal'))
model.compile(loss='mean_squared_error', optimizer='rmsprop', metrics=['mae'])

关于数据准备

data0 = renameColumns(addTimestampForwardShift(history[['year', 'month', 'day', 'hour', 'high']], timeShift), 0)
data1 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 1), -1)
data2 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 2), -2)
data3 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 3), -3)
data4 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 4), -4)
data5 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 5), -5)
data6 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 6), -6)
data7 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 7), -7)
data8 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 8), -8)
data9 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 9), -9)
data10 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 10), -10)
data11 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 11), -11)
data12 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 12), -12)
data13 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 13), -13)
data14 = renameColumns(addTimestampBackwardShift(history[['year', 'month', 'day', 'hour', 'high']], 14), -14)

data = pandas.merge(data0, data1, on=['timestamp'], how='left')
data = pandas.merge(data, data2, on=['timestamp'], how='left')
data = pandas.merge(data, data3, on=['timestamp'], how='left')
data = pandas.merge(data, data4, on=['timestamp'], how='left')
data = pandas.merge(data, data5, on=['timestamp'], how='left')
data = pandas.merge(data, data6, on=['timestamp'], how='left')
data = pandas.merge(data, data7, on=['timestamp'], how='left')
data = pandas.merge(data, data8, on=['timestamp'], how='left')
data = pandas.merge(data, data9, on=['timestamp'], how='left')
data = pandas.merge(data, data10, on=['timestamp'], how='left')
data = pandas.merge(data, data11, on=['timestamp'], how='left')
data = pandas.merge(data, data12, on=['timestamp'], how='left')
data = pandas.merge(data, data13, on=['timestamp'], how='left')
data = pandas.merge(data, data14, on=['timestamp'], how='right')

data = data.dropna()

data = data[['high0',
            'high-1',
            'high-2',
            'high-3',
            'high-4',
            'high-5',
            'high-6',
            'high-7',
            'high-8',
            'high-9',
            'high-10',
            'high-11',
            'high-12',
            'high-13',
            'high-14']]

normalized = (data - data.mean()) / (data.max() - data.min())
normalized = normalized.values

X = normalized[:, 1:]
Y = normalized[:, 0]

seed = int(time.time())
numpy.random.seed(seed)

model.fit(X, Y)

至于结果数据(timeshift = 12):

    year0  month0  day0  hour0  high0  timestamp  year-1  month-1  day-1  \
0   2014.0    12.0  28.0    0.0   5.15 2014-12-16  2014.0     12.0   15.0   
1   2014.0    12.0  29.0    0.0   5.72 2014-12-17  2014.0     12.0   16.0   
2   2014.0    12.0  30.0    0.0   5.95 2014-12-18  2014.0     12.0   17.0   
3   2014.0    12.0  31.0    0.0   5.75 2014-12-19  2014.0     12.0   18.0 
    hour-1  high-1  year-2  month-2  day-2  hour-2  high-2  year-3  month-3  \
0      0.0    5.21  2014.0     12.0   14.0     0.0    5.21  2014.0     12.0   
1      0.0    5.50  2014.0     12.0   15.0     0.0    5.21  2014.0     12.0   
2      0.0    5.90  2014.0     12.0   16.0     0.0    5.50  2014.0     12.0   
3      0.0    5.89  2014.0     12.0   17.0     0.0    5.90  2014.0     12.0   
rest according to the same pattern

1 个答案:

答案 0 :(得分:0)

  • 看看你的规范化功能。你需要替换" data.mean()"使用" data.min()"获得真正的最小 - 最大比例。此外,我会将数据之前扩展为将其分解为各个滞后功能。

    <sonar.jacoco.reportPaths>

  • 从仅有3-4个滞后变量开始(目前您从14开始)并逐步添加,每次添加都会测试性能,以确保它提高测试精度。

  • 如果要设置种子,请使用静态值进行重现性。否则没有理由设置种子,因为每次运行都会有所不同。

从那开始,看看是否从平面输出中改善了它。