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,n.ahead)
Arguments
Model |
Object of trained model. |
newdata |
The dataset for pediction, the column names must be the same as the trained data.Not required if type="dynamic". |
Type |
If Type="static", it computes the (static) forecasting values of insample model fit. If Type="dynamic", it recursively computes the forecasting values ahead. |
n.ahead |
For Type="dynamic", it is the number of forecasting periods ahead. Not required if type="static". |
Details
This function generates forecasts of tts.caret,and tts.autoML.
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","gbm","nb")[1]
type <- c("none","trend","season","both")[1]
# output <- tts.caret(y=dep, x=ind, arOrder=c(1), xregOrder=c(1),
# method="smv", tuneLength =1,
# train.end, type=type,resampling="cv",preProcess = "center")
# testData1 <- window(output$dataused,start="2019-01-01",end=end(output$dataused))
#P1=iForecast(Model=output,Type="static",newdata=testData1)
#P2=iForecast(Model=output,Type="dynamic",n.ahead=7)
#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 = tts.caret(y=dep, x=ind, arOrder=c(1), xregOrder=c(1), method="nb",
# tuneLength =10, train.end, type=type)
#testData1=window(output$dataused,start=test.start,end=end(output$dataused))
#head(output$dataused)
#P1=iForecast(Model=output,Type="static",newdata=testData1)
#P2=iForecast(Model=output,Type="dynamic",n.ahead=7)
#tail(cbind(testData1[,1],P1),10)
#tail(cbind(testData1[,1],P2),10)