使用LSTM Python进行多步单变量时间序列预测

时间:2019-11-13 09:11:31

标签: python time-series lstm

我正在使用LSTM模型处理多步单变量时间序列预测,我的目标是预测接下来的4个值。我尝试从machinelearningmastery以及部分代码和数据下面实施这些技术(split_sequence()): enter image description here

 ##########################  SKIP  ##########################################
 def split_dataset(dataset, fraction = 0.7):
    ## Split the dataset into train and test set ##
  train_size = int(len(dataset) * fraction)
  test_size = len(dataset) - train_size
  train_data, test_data = dataset[0:train_size,:], dataset[train_size:len(scaled_data),:]
  return train_data, test_data

 def split_sequence(sequence, n_steps_in, n_steps_out):
    ## Split a univariate sequence into samples ##
    X, y = list(), list()
    for i in range(len(sequence)):
        # find the end of this pattern
        end_ix = i + n_steps_in
        out_end_ix = end_ix + n_steps_out
        # check if we are beyond the sequence
        if out_end_ix > len(sequence):
            break
        # gather input and output parts of the pattern
        seq_x, seq_y = sequence[i:end_ix], sequence[end_ix:out_end_ix]
        X.append(seq_x)
        y.append(seq_y)
    return array(X), array(y)
 ##########################  SKIP  ##########################################
 n_steps_in= 48
 n_steps_out = 4
 # split dataset into train and test set
 train, test = split_dataset(scaled_data)
 # split into samples
 X_train, y_train = split_sequence(train, n_steps_in, n_steps_out)
 X_test, y_test = split_sequence(test, n_steps_in, n_steps_out)
 model = build_model(X_train, y_train, n_steps_in=48, n_steps_out = 4, epochs = 100, verbose = 10)

 # Forecast
 yhat = model.predict(X_test, verbose=10)
 print(scaler.inverse_transform(yhat))

输出

[[118.409355 118.404915 117.4196   118.88395 ]
[118.96226  119.02261  118.18034  119.03073 ]
[120.31018  120.47094  119.50547  119.7422  ]
...
[112.0476   110.57597  104.36442  106.43274 ]
[111.41764  110.17102  104.888405 106.87724 ]
[111.26458  110.009674 105.57218  106.981316]]

有人可以在下面解释/建议我的问题吗?

  1. 最后一行的4个值是否是全新的值?我曾经在LSTM上遇到问题,需要将X_test输入模型中以预测X_test本身(???)。
  2. 给出输出,如何评估RMSE分数?输入和输出的形状很荒谬,我无法使用任何库(例如sklearn)。
  3. 我的数据足够平稳吗?我认为Dickey-Fuller检验(1.098791e-14)的p值非常小,足够了。

0 个答案:

没有答案