iForecast: Extract predictions and class probabilities from train...

View source: R/ttsPredict.R

iForecastR 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="staticfit", it computes the direct (static) forecasting values of insample model fit; if type="recursive", it computes the recursive (dynamic) forecasting values of insample model; for recursive 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")[3]
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")
 testData1 <- window(Caret$data,start="2019-01-01",end=end(Caret$data))
P1 <- iForecast(Model=Caret,newdata=testData1,type="staticfit")
P2 <- iForecast(Model=Caret,newdata=testData1,type="recursive")

#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="staticfit")
#P2=iForecast(Model=Caret,newdata=testData1,type="recursive")

#tail(cbind(testData1[,1],P1),10)
#tail(cbind(testData1[,1],P2),10)


iForecast documentation built on July 9, 2022, 9:05 a.m.