我使用ARIMA进行了预测:
预测结果如下所示:
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
15552001 18.80470 18.52527 19.08413 18.37735 19.23206
15555601 18.94718 18.63358 19.26078 18.46758 19.42679
15559201 18.86774 18.53623 19.19924 18.36074 19.37473
15562801 18.84979 18.46603 19.23355 18.26288 19.43670
15566401 18.91506 18.52182 19.30830 18.31366 19.51646
15570001 18.86569 18.46538 19.26599 18.25347 19.47791
15573601 18.86727 18.45311 19.28143 18.23387 19.50067
15577201 18.89555 18.47853 19.31258 18.25777 19.53334
15580801 18.86784 18.44715 19.28854 18.22444 19.51125
15584401 18.87419 18.44782 19.30056 18.22212 19.52627
15588001 18.88546 18.45692 19.31399 18.23007 19.54085
15591601 18.87097 18.43914 19.30280 18.21054 19.53139
15595201 18.87679 18.44097 19.31262 18.21025 19.54334
15598801 18.88064 18.44225 19.31904 18.21018 19.55111
15602401 18.87349 18.43165 19.31533 18.19775 19.54923
15606001 18.87755 18.43210 19.32300 18.19630 19.55880
15609601 18.87844 18.43003 19.32685 18.19265 19.56423
15613201 18.87510 18.42320 19.32701 18.18397 19.56623
15616801 18.87759 18.42224 19.33293 18.18120 19.57397
15620401 18.87748 18.41899 19.33597 18.17627 19.57868
15624001 18.87602 18.41411 19.33793 18.16959 19.58245
15627601 18.87742 18.41219 19.34264 18.16592 19.58891
我想将此点转换为人类可读的日期时间。我该怎么做?
我的初始数据框的纪元时间为row.names,如:
y
1484337600 19.22819
1484341200 19.28906
1484344800 19.28228
1484348400 19.21669
1484352000 19.32759
1484355600 19.21833
1484359200 19.20626
1484362800 19.28737
1484366400 19.20651
1484370000 19.18424
我使用以下转换的初始数据集:
xts_dataframe <- xts(x = dataframe$y, order.by = as.POSIXct(as.numeric(row.names(dataframe)), origin="1970-01-01"))
fit <- auto.arima(ts_dataframe ,trace = TRUE,stepwise = FALSE) #411
fc <- forecast(fit,h=24)
fc <- as.POSIXct(as.numeric(fc$mean), origin = '1970-01-01')
print(fc)
现在提供这样的输出:
[1] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[3] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[5] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[7] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[9] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[11] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[13] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[15] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[17] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[19] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[21] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
[23] "1969-12-31 16:00:18 PST" "1969-12-31 16:00:18 PST"
没有预测结果。
问题-2:如果我没有做任何更改以指出我的预测结果:
fit <- auto.arima(ts_dataframe ,trace = TRUE,stepwise = FALSE)
fc <- forecast(fit,h=24)
print(fc)
我得到的结果是我在顶部发布的。在这个纪元时间是1970年,但它应该是在我的原始数据帧的最后一个纪元时间之后的东西。请帮忙。
答案 0 :(得分:2)
您可以查看新的sweep
包。这是描述该过程的recent post。以下输入基于您的数据框:
data
是您的数据框,其中列的日期或日期时间和一列值freq
是您的频率,start
是您ts
对象的开始h
是您未来的预测期这是一般过程。
library(forecast)
library(sweep)
library(timekit)
# Make ts with tk_ts()
data_ts <- tk_ts(data, freq = freq, start = start)
# auto.arima()
fit <- auto.arima(data_ts)
# Make forecast
fcast <- forecast(fit, h = h)
# Use sw_sweep with timekit_idx = TRUE
sw_sweep(fcast, timekit_idx = T)
答案 1 :(得分:1)
我希望这是您的数据的样子
> head(data)
epoch y
1 1484341200 19.28906
2 1484344800 19.28228
3 1484348400 19.21669
4 1484352000 19.32759
5 1484355600 19.21833
6 1484359200 19.20626
> data$epoch <- as.POSIXct(data$epoch, origin = '1970-01-01')
> head(data)
epoch y
1 2017-01-14 02:30:00 19.28906
2 2017-01-14 03:30:00 19.28228
3 2017-01-14 04:30:00 19.21669
4 2017-01-14 05:30:00 19.32759
5 2017-01-14 06:30:00 19.21833
6 2017-01-14 07:30:00 19.20626
> xts_dataframe <- xts(data$y, order.by = data$epoch)
> fit <- auto.arima(xts_dataframe ,trace = TRUE,stepwise = FALSE)
> fc <- forecast(fit,h=24)
> fc <- as.data.frame(fc)
> time1 <- as.data.frame(seq(tail(data$epoch,1)+60, length.out = nrow(fc), by = "30 min"))
> output <- as.data.frame(cbind(time1[,1],fc))
> print(output)