MASE提取层次结构数据("hts"和“预测"包R) [英] MASE Extraction Hierarchical Data ('hts' and 'forecast' packages R)

查看:281
本文介绍了MASE提取层次结构数据("hts"和“预测"包R)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从R中的精度函数(预测"包)中提取MASE(Hyndman等,2006).

I would like to extract the MASE (Hyndman et al., 2006) from the accuracy function ('forecast' package) in R.

我有17个时间序列,具有以下层次结构:

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))

,其中"matrix_tseries"是存储17个序列的矩阵.

, 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)

,其中"val_matrix_tseries"是一个矩阵,其中包含验证(超出样本)期内的实际值.

, where 'val_matrix_tseries' is a matrix containing the actuals in the validation (out of sample) period.

不幸的是,这只会生成ME,RMSE,MAE,MPE,MAPE,而不会生成MASE.

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.

推荐答案

有一个accuracy.gts函数可以做到这一点:

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)

注意:

  • 您对层次结构的指定没有任何意义.使用节点或bnames +字符,但不能同时使用.
  • 您有17个时间序列,但最底层只有14个时间序列. hts()仅需要底层序列.因此,我的示例使用14系列.
  • 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.

这篇关于MASE提取层次结构数据("hts"和“预测"包R)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆