I'm using a batch forecasting method for a dataframe (name:df5) that looks like this:
Primary.Base.Product Variable Value
A Aug '16 1
A Sep '16 4
B Aug '16 10
B Sep '16 2
Z Aug '16 6
Z Sep '16 12
I tried the DPLYR code suggested by ramhiser here : For loop for forecasting several datasets at once in R
library(dplyr)
library(smooth)
library(forecast)
library(tstools)
#Create a DF
Primary.Base.Product <- c('A','A','B','B','C','C')
variable <- c('Aug16','Sep16','Aug16','Sep16','Aug16','Sep16')
value <- c(1,4,10,2,6,12)
df5 = data.frame(Primary.Base.Product,variable,value)
#Do Batch Forecasting:
model_fits2 <- group_by(df5, Primary.Base.Product) %>% do(fit=ets(.$value))
head(model_fits2)
forecast(model_fits2$fit[[1]])
It works fine but how do I split the data into test and train and calculate the accuracy using accuracy() function? Also, how do I calculate the accuracy of fitted values versus actual values?
Any sort of help is appreciated! Thanks in advance!
I've tried:
model_fits2 <- group_by(df5, Primary.Base.Product) %>%
do(fit=ets(.$value[1:(nrow(df5)-10)]))
model_acc2 <- group_by(df5, Primary.Base.Product) %>%
do(acc=accuracy(.$value[(nrow(df5)+1):nrow(df5)],
forecast(model_fits2$fit,h=10)))
The error was:
Error in ets(object, lambda = lambda, biasadj = biasadj, allow.multiplicative.trend = allow.multiplicative.trend, : y should be a univariate time series