2017-10-13 47 views
0

我想使用ETS来应用Holt-Winters。我正在读取数据库中的数据,因为不同用户的开始时间戳可能会有所不同(但时间间隔保持在15分钟)。使用ETS绘制预测输出

我在绘制/解释预测结果时遇到了问题。 x轴可能会显示时间序列的索引值。我无法确定问题。下面的采样数据是:

> rawdata 
    date_time_start total_transmitted_mbps 
    25/04/2017 00:00 8091.22258 
    25/04/2017 00:15 8669.16705 
    25/04/2017 00:30 6742.03133 
    25/04/2017 00:45 7637.89432 
    25/04/2017 01:00 7190.45344 
    25/04/2017 01:15 9798.56278 
    25/04/2017 01:30 7136.48579 
    25/04/2017 01:45 6255.34125 
    25/04/2017 02:00 6315.19628 
    25/04/2017 02:15 6306.36521 
    25/04/2017 02:30 9749.50128 
    25/04/2017 02:45 8247.23815 
    25/04/2017 03:00 9629.79122 
    25/04/2017 03:15 9316.77885 
    25/04/2017 03:30 9877.06118 
    25/04/2017 03:45 8909.5684 
    25/04/2017 04:00 7853.76492 
    25/04/2017 04:15 8877.18781 
    25/04/2017 04:30 6856.83524 
    25/04/2017 04:45 9037.1283 

格式化时间序列保留输入时间格式:

raw_data$date_time_start <- 
    as.POSIXct(strptime(paste(as.character(raw_data$date_time_start),":00",sep = ""), 
         format="%d/%m/%Y %H:%M:%S")) 
eventdata <- xts(raw_data$total_cir_transmitted_mbps, 
       order.by = raw_data$date_time_start) 
plot(eventdata) # plot is OK 

此输入的情节确定。 enter image description here

我用ets如下:

fit2<-ets(eventdata, model="ZZZ", damped=TRUE, alpha=NULL, beta=NULL, gamma=NULL)  
fcast90 <- forecast(fit2, h=100) 
    plot(fcast100) # x-axis of plot is incorrect 

enter image description here

我注意到,当我fcast90$x我能看到的输出。预测中接下来的100个时间段的时间戳不包含在输出中?

> fcast90$x 
    Time Series: 
    Start = 1 
    End = 11521 
    Frequency = 0.0166666666666667 
     [1] 8091.223 8669.167 6742.031 7637.894 7190.453 9798.563 7136.486 6255.341 6315.196 
[10] 6306.365 9749.501 8247.238 9629.791 9316.779 9877.061 8909.568 7853.765 8877.188 

如何预测和查看接下来的100天?

更新 基于@ A5C1D2H2I1M1N2O1R2T1和@joran的帖子,我想两件事情:

  1. 生成日期的顺序(格式:YYYY-MM-DD)

  2. 设置axes = FALSE在情节中,并且标记我们自己的坐标轴。

我无法获得#2个工作

随着#1,在我的数据,开始日期应为用户之间的不同。为了尝试@ A5C1D2H2I1M1N2O1R2T1的建议,我假定开始日期是固定的。我读了第一次约会,并最后为该用户获取频率。

aa <- raw_data[1,] # to obtain the start date 
bb <- raw_data[nrow(raw_data),] # to obtain the last date using the nrow 

由于每个用户的开始/结束时间可能不同,我正在计算时间序列中的天数。 time_diff天应该等于预测数据点fcast90 <- forecast(fit2, fcast_days+time_diff)

fcast_days = 100 
startDate = as.POSIXct(strptime(paste(as.character(aa$date_time_start),":00",sep = ""), format="%d/%m/%Y %H:%M:%S")) 
endDate = as.POSIXct(strptime(paste(as.character(bb$date_time_start),":00",sep = ""), format="%d/%m/%Y %H:%M:%S")) 
time_diff = as.numeric(round(endDate - startDate)) # output=16 

生成的情节序列标签

a = seq(as.Date(startDate), by="days", length=time_diff+fcast_days) #length = 116 

但我打了一个问题,当我使用seq因为seq最低的粒度是days。我的时间间隔为15分钟。所以我被迫读入数据而不是生成数据。出于这个原因,我使用raw_data$date_time_start <- as.POSIXct(strptime(paste(as.character(raw_data$date_time_start),":00",sep = ""),format="%d/%m/%Y %H:%M:%S"))。请告知这是错误的。

用#2,我设置axes = FALSE只打印日期。重新使用代码的链接:

fcast90 <- forecast(fit2, fcast_days+time_diff) 
plot(fcast90, axes = FALSE) 
axis(1, at = a, labels = format(a, "%d %b %Y"), cex.axis=0.6) 
abline(v = decimal_date(a), col='grey', lwd=0.5) 
axis(2, cex.axis=0.6) 

我认为在情节的问题是由于不相配的天在seq,数据点fcast90$x数量。

> length(fcast90$x) # represents data captured at 15 min interval 
[1] 1536 
> length(a) # repesents number of days 
[1] 116 

对于我有的时间系列,我的步骤是否正确?

+0

我想这里讨论的是相同的:https://stackoverflow.com/questions/10302261/forecasting-time-series-data – Adam

+0

非常感谢您指出以前的职位。它在我以前的搜索中没有显示出来。我已根据您分享的链接更新了我的帖子。我仍然无法成功绘制输出 –

回答

0

检查forecast文档。

fcast90$meanfcast90$lowerfcast90$higher应该给你你要找的。

+0

确实'fcast90 $ x'显示我的'预测(fit2,fcast_days + time_diff)'输出。但是,数据点的数量与我生成的用于更改绘图轴的天数不匹配。 –