【问题标题】:Time series forecasting with NARX in R在 R 中使用 NARX 进行时间序列预测
【发布时间】:2019-02-10 09:01:12
【问题描述】:

我想使用 NARX(具有外生输入的非线性自回归网络)进行时间序列预测,我正在拼命地在 R 中寻找合适的包和函数。 这个论坛中对同一问题的其他答案提出了

  • tsDyn 包的nnetTs() 或
  • nnetar() 在 forecast 包中。另外我发现了
  • elm() 包中的 elm() 函数。

但它们似乎都不等同于例如 Matlab 中的 NARX 模型,这是我试图避免的。

nnetTs() 没有外生输入变量(又名外部回归变量)的参数,这对 NARX 模型至关重要。 nnetar() 具有这些外部回归量并且是自回归的,但没有提供设置回归量滞后的参数。

最后的问题是:R 中是否存在真正的 NARX 等价物?

【问题讨论】:

  • 欢迎来到 SO;请花一些时间阅读What topics can I ask about here?,并注意要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题在此处不属于主题。

标签: r machine-learning neural-network time-series forecasting


【解决方案1】:

R中nnfor包的mlp函数,相当于NARX。此函数提供外部回归量和滞后量:

xreg:外生回归量。每列是一个不同的回归量,并且 样本大小必须至少与目标样本内集一样长, 但可以更长。

xreg.lags:这是一个包含滞后的列表 每个外生变量。每个列表都是一个数值向量,包含 滞后。如果 xreg 有 3 列,则 xreg.lags 列表必须包含三个 元素。如果为 NULL 则自动指定。

请参阅下面的example by Nikolaos Kourentzes:

library(nnfor)
# The objective is to forecast the Airline Passengers series with only deterministic trend and seasonality
# mlp does the deterministic seasonality internally, when needed, but not the trend.

# Let us prepare some data
y <- AirPassengers
plot(y)
h <- 2*frequency(y)
tt <- cbind(c(1:(length(y)+h),rep(0,2*h)))
plot(tt)
# Observe that the deterministic trend ends with zeros
print(tt)

# Fit a network with no differencing, no univariate lags, and fixed deterministic trend
fit1 <- mlp(y,difforder=0,lags=0,xreg=tt,xreg.lags=list(0),xreg.keep=TRUE)
print(fit1)
plot(fit1)
plot(forecast(fit1,h=h,xreg=tt))
# The forecast is reasonable

# Now let us shift the input so that the zeros are in the forecast period
tt2 <- tt[-(1:h),,drop=FALSE]
plot(forecast(fit1,h=h,xreg=tt2))
# The seasonality is there, but there is zero trend, as the inputs suggest. 
# Also note that the mlp modelled multiplicative seasonality on its own. NNs are cool. 

# Now let us fit a network on the shifted inputs
# I will ask for outplot=1 to see the model fit
fit2 <- mlp(y,difforder=0,lags=0,xreg=tt2,xreg.lags=list(0),xreg.keep=TRUE,outplot=1)
plot(fit2)
plot(forecast(fit2,h=h,xreg=tt2))
# Same as before

# Now lets fit with two inputs, the shifted (lead of 24 periods) and the original trend
fit3 <- mlp(y,difforder=0,lags=0,xreg=cbind(tt[1:192,,drop=FALSE],tt2),xreg.lags=list(0,0),xreg.keep=list(TRUE,TRUE),outplot=1)
print(fit3)
plot(fit3)
plot(forecast(fit3,h=h,xreg=cbind(tt[1:192,,drop=FALSE],tt2)))
# The network gets a bit confused with one of the trend vectors stopping!

【讨论】:

    猜你喜欢
    • 2012-12-25
    • 2018-12-23
    • 2017-08-28
    • 2015-10-01
    • 2014-04-03
    • 2017-12-21
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多