问题
I would like to extract the MASE (Hyndman et al., 2006) from the accuracy function ('forecast' package) in R.
I have 17 time series with the following hierarchical structure:
nodes <- list(2, c(7,7))
hierarchical <- hts(matrix_tseries, nodes, bnames = colnames_bottom, characters = c(1,1))
, where 'matrix_tseries' is a matrix that stores the 17 series.
I have then calculated the forecasts for each series and would like to extract the assessment metrics for the desired horizon:
fcast <- forecast(hierarchical, h = 35 ,level = c(80,95),
fmethod = "ets", method = "comb")
accuracy(fcast$bts[,1], val_matrix_tseries[,1], test=NULL, d=NULL, D=NULL)
, where 'val_matrix_tseries' is a matrix containing the actuals in the validation (out of sample) period.
Unfortunately this only produces ME, RMSE, MAE, MPE, MAPE but not MASE.
I've found a potential solution here but wasn't able to provide the historical data information in the way needed to calculate the scaling factor.
回答1:
There is an accuracy.gts
function to do this:
library(hts)
# Generate some artificial data
matrix_tseries <- ts(matrix(rnorm(14*75),ncol=14))
nodes <- list(2, c(7,7))
# Split data into training and test sets
hierarchical <- hts(window(matrix_tseries, end=40), nodes)
test <- hts(window(matrix_tseries, start=41), nodes)
# Produce forecasts
fcast <- forecast(hierarchical, h = 35 ,level = c(80,95),
fmethod = "ets", method = "comb")
# Compute accuracy measures
accuracy.gts(fcast, test)
Notes:
- Your specification of the hierarchy makes no sense. Use either nodes or bnames + characters, but not both.
- You have 17 time series, but only 14 at the bottom level.
hts()
only requires the bottom level series. Hence, my example uses 14 series.
来源:https://stackoverflow.com/questions/38971664/mase-extraction-hierarchical-data-hts-and-forecast-packages-r