iForecast | R Documentation |
It generates both the static and recursive time series plots of machine learning prediction object generated by ttsCaret, ttsAutoML and ttsLSTM.
iForecast(Model,newdata,type)
Model |
Object of trained model. |
newdata |
The dataset for pediction, the column names must be the same as the trained data. |
type |
If type="static", it computes the (static) forecasting values of insample model fit. If type="dynamic", it iteratively computes the multistep forecasting values given the insample estimated model. For dynamic forecasts, AR term is required. |
This function generates forecasts of ttsCaret,ttsAutoML, and ttsLSTM.
prediction |
The forecasted time series target variable. For binary case, it returns both porbabilities and class. |
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
# Cross-validation takes time, example below is commented.
## Machine Learning by library(caret)
#Case 1. Low frequency, regression type
data("macrodata")
dep <- macrodata[569:669,"unrate",drop=FALSE]
ind <- macrodata[569:669,-1,drop=FALSE]
train.end <- "2018-12-01"# Choosing the end dating of train
models <- c("svm","rf","rpart")[1]
type <- c("none","trend","season","both")[1]
#output <- ttsCaret(y=dep, x=ind, arOrder=c(1), xregOrder=c(1),
# method=models, tuneLength =1, train.end, type=type,resampling="cv",preProcess = #"center")
# testData1 <- window(output$data,start="2019-01-01",end=end(output$data))
#P1 <- iForecast(Model=output,newdata=testData1,type="static")
#P2 <- iForecast(Model=output,newdata=testData1,type="dynamic")
#tail(cbind(testData1[,1],P1))
#tail(cbind(testData1[,1],P2))
#Case 2. Low frequency, binary type
data(bc) #binary dependent variable, business cycle phases
dep=bc[,1,drop=FALSE]
ind=bc[,-1]
train.end=as.character(rownames(dep))[as.integer(nrow(dep)*0.8)]
test.start=as.character(rownames(dep))[as.integer(nrow(dep)*0.8)+1]
#output = ttsCaret(y=dep, x=ind, arOrder=c(1), xregOrder=c(1), method=models,
# tuneLength =10, train.end, type=type)
#testData1=window(output$data,start=test.start,end=end(output$data))
#head(output$dataused)
#P1=iForecast(Model=output,newdata=testData1,type="static")
#P2=iForecast(Model=output,newdata=testData1,type="dynamic")
#tail(cbind(testData1[,1],P1),10)
#tail(cbind(testData1[,1],P2),10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.