简体   繁体   English

预测分层时间序列

[英]Forecasting Hierarchical Time Series

I am trying to perform 6 months forecasting over production data for three power plants, I built my data as an hts object that has 3 levels. 我试图对三个发电厂的生产数据进行6个月的预测,我将数据构建为具有3个级别的hts对象。 However, when I am performing the forecast function and then try to see the accuracy using test data I get the following error: "Error in x - fcasts: non-conformable arrays" 但是,当我执行预测功能,然后尝试使用测试数据查看准确性时,出现以下错误:“ x中的错误-fcasts:不一致的数组”

在此处输入图片说明

Furthermore, when I try to apply the "arima" as a forecasting method on the hts object I get the following (the warning message is repeated 9 times, as I have 9 time series in the hts object): 此外,当我尝试对“ hts”对象应用“ arima”作为预测方法时,我得到以下信息(警告消息重复了9次,因为我在hts对象中有9个时间序列):

forecasts <- forecast(data,h = 6 , method = "bu" , fmethod = "arima") 预测<-预测(数据,h = 6,方法=“ bu”,fmethod =“ arima”) 在此处输入图片说明

I used the following instructions to get the hts object: 我使用以下说明来获取hts对象:

在此处输入图片说明

and the data has the following structure: 数据具有以下结构: 在此处输入图片说明 I am not sure where I am going wrong. 我不确定我要去哪里错。 Anyone can help with some thoughts?? 任何人都可以提供一些想法吗?

Thank you! 谢谢!

The data: 数据:

structure(list(LarGroup1 = c(188.3, 187.2, 94.7, 109.2, 202.7, 
146.6, 121.9, 151.3, 111.1, 103.4, 188.1, 168.1, 233.9, 230.7, 
187.1, 0, 98.9, 173.5, 149.4, 168.6, 4.7, 14.8, 91.8, 166.5, 
170.5, 123.6, 85.2, 64.4), LarGroup2 = c(159.1, 127.7, 210.3, 
199.8, 113, 143.4, 144.5, 83.8, 41.6, 35.1, 95.2, 178.2, 241.1, 
236.4, 181.9, 194.3, 196.1, 92.4, 154.6, 78.9, 35.7, 0, 74.5, 
75.1, 140, 142.5, 3.8, 17.5), RibGroup1 = c(49.4, 102.4, 50.8, 
118.8, 108.4, 139.5, 121.7, 69.6, 53.4, 28, 113.3, 96.3, 70.8, 
124.4, 54.4, 128.7, 63.3, 2.1, 41.3, 0.4, 0.6, 0, 5.4, 57.9, 
9.9, 30, 221, 167.2), RibGroup2 = c(32.7, 32, 98.1, 6.3, 85.5, 
96.6, 41.1, 44.9, 50.4, 27.3, 0, 45.4, 199.1, 179.2, 86.1, 0, 
58.4, 43.3, 41.8, 42.1, 22.1, 11.8, 71.8, 112, 204.1, 40.9, 24.5, 
210.9), RibGroup3 = c(90.8, 15.4, 10.5, 124.4, 33.9, 8.4, 38.3, 
56.9, 13.5, 0, 32.6, 132.8, 160.7, 168.7, 60.7, 131.9, 110.8, 
29.2, 131.3, 62.1, 6.1, 0, 0, 3.4, 23.9, 192.7, 165.5, 0), SinGroup1 = c(235.2, 
225.4, 226.1, 234.4, 222.1, 232.3, 233.4, 201.9, 195.3, 209.4, 
233.6, 223.6, 222.2, 232, 224, 149.8, 201.6, 220.2, 203.1, 212.1, 
71.9, 82.3, 183.2, 210.6, 198.6, 230.8, 218, 163.2), SinGroup2 = c(233.4, 
225.6, 227, 51.6, 76, 230.7, 233.1, 202.7, 200.2, 207.2, 228.4, 
226.2, 183.9, 230.4, 222.3, 227.7, 177.9, 152, 218.6, 210.6, 
80.9, 63.2, 188.1, 209.5, 233.2, 210.1, 226.5, 200.5), SinGroup3 = c(233.2, 
188.5, 226.9, 234.7, 222.8, 234.6, 220.6, 156.4, 209.2, 218.7, 
232.9, 226.1, 215.4, 231, 222.7, 222.7, 183.7, 203.8, 216.8, 
112, 0, 39.6, 180.8, 203.6, 221.1, 228.9, 202.8, 186.7), SinGroup4 = c(218, 
215.5, 226.8, 235.6, 223.6, 234.8, 234.9, 69.3, 192, 207.8, 235.2, 
217.2, 235.1, 231.8, 223.5, 230.5, 225.6, 220.1, 220, 211.9, 
114.8, 44.5, 158.5, 206.3, 231.8, 179, 225.3, 198.6)), class = "data.frame", row.names = c(NA, 
-28L))
  1. In the accuracy function, you need to include test data, not training data. 在准确性功能中,您需要包括测试数据,而不是训练数据。 You ask for 6 steps ahead, but your test data only consists of 4 time periods. 您要求提前6个步骤,但是您的测试数据仅包含4个时间段。

  2. The seasonal differencing error suggests you are using an old version of the forecast package. 季节性差异错误表明您使用的是预报包的旧版本。 Please update your packages. 请更新您的软件包。

The following code works using current CRAN packages (forecast v8.4, hts v 以下代码使用当前的CRAN程序包运行(预测v8.4,hts v

library(hts)
Production_data <- data.frame(
  LarGroup1 = c(
    188.3, 187.2, 94.7, 109.2, 202.7,
    146.6, 121.9, 151.3, 111.1, 103.4, 188.1, 168.1, 233.9, 230.7,
    187.1, 0, 98.9, 173.5, 149.4, 168.6, 4.7, 14.8, 91.8, 166.5,
    170.5, 123.6, 85.2, 64.4
  ), LarGroup2 = c(
    159.1, 127.7, 210.3,
    199.8, 113, 143.4, 144.5, 83.8, 41.6, 35.1, 95.2, 178.2, 241.1,
    236.4, 181.9, 194.3, 196.1, 92.4, 154.6, 78.9, 35.7, 0, 74.5,
    75.1, 140, 142.5, 3.8, 17.5
  ), RibGroup1 = c(
    49.4, 102.4, 50.8,
    118.8, 108.4, 139.5, 121.7, 69.6, 53.4, 28, 113.3, 96.3, 70.8,
    124.4, 54.4, 128.7, 63.3, 2.1, 41.3, 0.4, 0.6, 0, 5.4, 57.9,
    9.9, 30, 221, 167.2
  ), RibGroup2 = c(
    32.7, 32, 98.1, 6.3, 85.5,
    96.6, 41.1, 44.9, 50.4, 27.3, 0, 45.4, 199.1, 179.2, 86.1, 0,
    58.4, 43.3, 41.8, 42.1, 22.1, 11.8, 71.8, 112, 204.1, 40.9, 24.5,
    210.9
  ), RibGroup3 = c(
    90.8, 15.4, 10.5, 124.4, 33.9, 8.4, 38.3,
    56.9, 13.5, 0, 32.6, 132.8, 160.7, 168.7, 60.7, 131.9, 110.8,
    29.2, 131.3, 62.1, 6.1, 0, 0, 3.4, 23.9, 192.7, 165.5, 0
  ), SinGroup1 = c(
    235.2,
    225.4, 226.1, 234.4, 222.1, 232.3, 233.4, 201.9, 195.3, 209.4,
    233.6, 223.6, 222.2, 232, 224, 149.8, 201.6, 220.2, 203.1, 212.1,
    71.9, 82.3, 183.2, 210.6, 198.6, 230.8, 218, 163.2
  ), SinGroup2 = c(
    233.4,
    225.6, 227, 51.6, 76, 230.7, 233.1, 202.7, 200.2, 207.2, 228.4,
    226.2, 183.9, 230.4, 222.3, 227.7, 177.9, 152, 218.6, 210.6,
    80.9, 63.2, 188.1, 209.5, 233.2, 210.1, 226.5, 200.5
  ), SinGroup3 = c(
    233.2,
    188.5, 226.9, 234.7, 222.8, 234.6, 220.6, 156.4, 209.2, 218.7,
    232.9, 226.1, 215.4, 231, 222.7, 222.7, 183.7, 203.8, 216.8,
    112, 0, 39.6, 180.8, 203.6, 221.1, 228.9, 202.8, 186.7
  ), SinGroup4 = c(
    218,
    215.5, 226.8, 235.6, 223.6, 234.8, 234.9, 69.3, 192, 207.8, 235.2,
    217.2, 235.1, 231.8, 223.5, 230.5, 225.6, 220.1, 220, 211.9,
    114.8, 44.5, 158.5, 206.3, 231.8, 179, 225.3, 198.6
  )
)
Production_data_ts <- ts(Production_data, frequency = 12, start = c(2016, 7))
Production_data_hts <- hts(Production_data_ts, characters = c(3, 6))
data <- window(Production_data_hts, start = c(2016, 7), end = c(2018, 6))
test <- window(Production_data_hts, start = c(2018, 7), end = c(2018, 10))
forecasts <- forecast(data, h = 4, method = "bu")
accuracy(forecasts, test)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM