Closed Steviey closed 4 years ago
For a 1-step or multi-step ahead forecasts that include XREGS (e.g. lags, events, etc), you need to use new_data
providing all columns with the exception of the target column (optionally the target can be encoded as NA values). This means you need to supply the Xregs as part of the future data frame.
OK, I understand Matt. Is it right to forecast the xregs for the future data frame e.g. with a default ets-method from package forecast?...
allData<-as_tibble(sampleData)
futureDf<-tail(allData,n=sSize)
modelXreg<-function(allData,title,h,n){
what1<-tail(allData,n=n)
what1$date <- as.Date(what1$date,format="%Y-%m-%d")
what1<-what1[,c('date',title)]
what1 <-tibble::as_tibble(what1)
what1<-tk_ts(what1,start=1,freq=1, silent = TRUE)
fcMyXreg<- forecast::forecast(what1,h=h)$mean
fcMyXreg<-as.numeric(fcMyXreg)
return(fcMyXreg)
}
myFuture<- futureDf %>% timetk::future_frame(.date_var=date,.length_out=myH,.inspect_weekdays=TRUE,.inspect_months = TRUE)
myFuture$myXreg<-modelXreg(allData,'myXreg',h=myH,n=sSize)
unseenPredictTib<-calibration_table %>%
modeltime_refit(model_table,data=allData) %>%
modeltime_forecast(new_data=myFuture,actual_data=allData)
Is this the right strategy? Thank you, for your advise Matt!
For a 1-step or multi-step ahead forecasts that include XREGS (e.g. lags, events, etc), you need to use
new_data
providing all columns with the exception of the target column (optionally the target can be encoded as NA values). This means you need to supply the Xregs as part of the future data frame.
How does this work if the lags are of the outcome variable you are trying to forecast? This was helpful in the M5 competition I think. I tried to include step_lag(all_outcomes(), lag = 1:7) but this alone will not work. What other steps to I have to take to make a forecast e.g. 14 days into the future?
Don't create lags as a preprocessing step inside of your preprocessing recipe. Rather create the lags outside of your recipe.
In the upcoming Time Series course, I teach you to:
Ok I see. Looking forward to the course!
Yes - There is a strategy. :)
Ubuntu: 16.4 LTS, R: 4.0.2, modeltime: 0.0.2
Thank you Matt for the marvelous code.
I can't find any documentation/information how to refit and forecast 1 day ahead, using exogenous regressors.
In the forecast package by Prof. Hyndman I would say:
arima.forecast <- forecast(arima.model,h=myH,xreg=newRegressors,biasadj=T)
When I say...
... I get data by type actual and forecast until the last day contained in splits. But I want to forecast one unseen day ahead, including exogenous regressors used while training.
In regard to "modeltime_forecast()" I read about a future tibble. But then the documentation PDF ends... "Forecasting Future Data: See future_frame() for creating future tibbles." "future_frame()" seems to be a dead link.
Are there any hints available- or a small code example?
Thank you.