0

我正在尝试使用 ETS 申请 Holt-Winters。我正在从数据库中读取数据,因为不同用户的开始时间戳可能不同(但间隔保持在 15 分钟)。

我在绘制/解释预测结果时遇到问题。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

这个输入的情节是好的。在此处输入图像描述

我正在使用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

在此处输入图像描述

我注意到当我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

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

4

1 回答 1

0

检查预测文档。

fcast90$meanfcast90$lower或者fcast90$higher应该给你你正在寻找的东西。

于 2017-10-13T07:45:32.393 回答