iForecast {iForecast} | R Documentation |
Extract predictions and class probabilities from train objects
Description
It generates both the static and recursive time series plots of machine learning prediction object generated by ttsCaret, ttsAutoML and ttsLSTM.
Usage
iForecast(Model,newdata,type)
Arguments
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. |
Details
This function generates forecasts of ttsCaret,ttsAutoML, and ttsLSTM.
Value
prediction |
The forecasted time series target variable. For binary case, it returns both porbabilities and class. |
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
# 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]
#Caret <- 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(Caret$data,start="2019-01-01",end=end(Caret$data))
#P1 <- iForecast(Model=Caret,newdata=testData1,type="static")
#P2 <- iForecast(Model=Caret,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]
#Caret = ttsCaret(y=dep, x=ind, arOrder=c(1), xregOrder=c(1), method=models,
# tuneLength =10, train.end, type=type)
#testData1=window(Caret$data,start=test.start,end=end(Caret$data))
#head(Caret$dataused)
#P1=iForecast(Model=Caret,newdata=testData1,type="static")
#P2=iForecast(Model=Caret,newdata=testData1,type="dynamic")
#tail(cbind(testData1[,1],P1),10)
#tail(cbind(testData1[,1],P2),10)