I am using dynamic Regression model to forecast a minute by minute time-series. However, the forecast period do not match the specified 'h' value. but they rather match the length of the training dataset. The training dataset is of 2 weeks, whereas the test dataset is 1 week, with minute by minute granularity. I speify h = 60*24*7 =10080 minutes (for 1 week) in the forecast() function , however, the forecast length is 20160 which is two weeks.
I checked if there is any correlation with the length of the training set. Apparently, there is. If I input three weeks of training dataset, it will produce three weeks of forecast.
xreg <- fourier(msts_train_10, K= c(15,5))
fit4 <- auto.arima(msts_train_10, xreg=xreg, seasonal=FALSE, stationary=TRUE)
fc4 <- forecast(fit4, xreg = xreg, h = 10080)
accuracy(fc4,msts_total)
autoplot(fc4)
> length(fc4$mean)
[1] 20160
I expect just 1 week of forecast (10080 values) to be produced. How can this error be fixed ?
Please take the time to read the help files. In this case, they provide a simple solution.
h : Number of periods for forecasting. If xreg is used, h is ignored and the number of forecast periods is set to the number of rows of xreg.
Since you used fourier()
to generate xreg
, and you didn't use the h
argument in that function, xreg
will have as many rows as the training data. (Again, try reading the help file.)