Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
R 用于时间序列预测的LSTM网络_R_Time Series_Lstm - Fatal编程技术网

R 用于时间序列预测的LSTM网络

R 用于时间序列预测的LSTM网络,r,time-series,lstm,R,Time Series,Lstm,我有一个大小为64的单变量月度时间序列。我想用剩下的几个月作为训练集,做一个多步骤的预测——过去三个月的值(266、286和230) data <- c(113, 55, 77, 114, 73, 72, 75, 135, 84, 66, 167, 93, 83, 164, 76, 97, 148, 74, 76, 173, 70, 86, 167, 37, 1, 49, 48,37, 117, 178, 1

我有一个大小为64的单变量月度时间序列。我想用剩下的几个月作为训练集,做一个多步骤的预测——过去三个月的值(266、286和230)

data <- c(113,  55,  77, 114,  73,  72,  75, 135,  84,  66, 167, 93,  83, 
          164,  76,  97, 148,  74,  76, 173,  70,  86, 167,  37,   1,  49,  
          48,37, 117, 178, 167, 177, 295, 167, 224, 225, 198, 217, 220, 175, 
          360, 289, 209, 369, 287, 249, 336, 219, 288, 248, 370, 296, 337, 
          246, 377, 324, 288, 367, 309, 128, 382, 266, 286, 230)
然而,当我按照下面的方式设置LSTM时,我得到了一个错误

Error in py_call_impl(callable, dots$args, dots$keywords) : 
ValueError: Error when checking target: expected time_distributed_16 to have 
shape (6, 1) but got array with shape (3, 1)
LSTM模型

model <- keras_model_sequential()

model %>%
  layer_lstm(
              units = 32, 
              batch_input_shape  = c(1, 6, 1),
              dropout = 0.2,
              recurrent_dropout = 0.2,
              return_sequences = TRUE
  ) %>% time_distributed(layer_dense(units = 1))

  model %>%
      compile(loss = FLAGS$loss, optimizer = optimizer, metrics = 
              list("mean_squared_error"))

  history <- model %>% fit(x = X_train,
                           y = Y_train,
                           batch_size = 1,
                           epochs = 100,
                           callbacks = callbacks)
型号%
图层(
单位=32,
批次输入形状=c(1,6,1),
辍学率=0.2,
经常性辍学=0.2,
return\u sequences=TRUE
)%%>%时间分布(层密度(单位=1))
型号%>%
编译(损失=标志$loss,优化器=优化器,度量=
列表(“均方误差”)
历史拟合百分比(x=x_列,
y=y_列车,
批次大小=1,
纪元=100,
回调=回调)

我正在与这个错误作斗争。有人知道这种建模的概念错误吗?提前感谢。

由于数据太少,您可能无法利用LSTM神经网络的优势。我建议您使用预测软件包中的SARIMA或HW。如果滞后之间存在一些非文学性,您还可以使用更相关的滞后和使用傅立叶级数提取的季节性成分构建数据集,并训练随机森林模型

关于你的问题,我认为你的数组没有正确的维度,因此你需要重新塑造它们

我不是LSTM神经网络专家,但下面的链接可能会帮助您:

model <- keras_model_sequential()

model %>%
  layer_lstm(
              units = 32, 
              batch_input_shape  = c(1, 6, 1),
              dropout = 0.2,
              recurrent_dropout = 0.2,
              return_sequences = TRUE
  ) %>% time_distributed(layer_dense(units = 1))

  model %>%
      compile(loss = FLAGS$loss, optimizer = optimizer, metrics = 
              list("mean_squared_error"))

  history <- model %>% fit(x = X_train,
                           y = Y_train,
                           batch_size = 1,
                           epochs = 100,
                           callbacks = callbacks)