使用 R - 需要根据不规则时间序列预测明年的建议
Using R - Need advice predicting next year based on irregular time-series
我需要有关以下查询的建议:"Based on your observations, what could you say about the load for the same months in year 2019?"
df 的 str()/head() 看起来像这样:
data.frame': 683 obs. of 10 variables:
$ Route : chr "A" "B" "A" "A" ...
$ FlightNumber: int 770 279 128 235 434 543 556 663 770 279 ...
$ Capacity : int 375 345 375 375 375 375 375 375 375 345 ...
$ Booked : int 379 314 374 379 373 377 379 378 379 294 ...
$ DDate : Date, format: "2018-05-01" "2018-05-01" "2018-05-02" "2018-05-03" ...
$ Year : num 2018 2018 2018 2018 2018 ...
$ Month : num 5 5 5 5 5 5 5 5 5 5 ...
$ Day : int 1 1 2 3 4 5 6 7 8 8 ...
$ Hour : int 12 20 12 12 12 12 12 12 12 20 ...
$ load : num 1.011 0.91 0.997 1.011 0.995 ...
Route FlightNumber Capacity Booked DDate Year Month Day Hour load(=Booked/Capacity)
1 A 770 375 379 2018-05-01 2018 5 1 12 1.0106667
2 B 279 345 314 2018-05-01 2018 5 1 20 0.9101449
3 A 128 375 374 2018-05-02 2018 5 2 12 0.9973333
4 A 235 375 379 2018-05-03 2018 5 3 12 1.0106667
5 A 434 375 373 2018-05-04 2018 5 4 12 0.9946667
6 A 543 375 377 2018-05-05 2018 5 5 12 1.0053333
如果我绘制数据,它看起来像这样:geom_point
更新:我最后做了以下事情:
dat_A <- test %>% select(Route, DDate, load) %>% filter(Route == "A")
ts_A <- ts(dat_A$load, start = c(2017,5), end = c(2018,11), frequency = 1*12)
forecast(ts_A, h=12) %>% plot()
Predicted outcome image
#Double checking
fit <- auto.arima(ts_A)
summary(fit)
predict <- forecast(fit,n=1)
plot(predict)
plot.ts(predict$residuals)
qqnorm(predict$residuals)
acf(predict$residuals)
预测靠谱吗?看起来相当平坦,尽管我也尝试通过 arima 进行 train(1:480)/validat(481:611) 然后以 RMSE 为 0.036 进行预测...
要将 vector
或 data.frame
转换为时间序列,您可以使用:
dat <- as.ts(as.matrix(dat))
您可以尝试以下解决方案。我可以指导您使用以下函数生成时间序列。首先加载你的数据说它是 df
并且它有列 Booked
所以你可以使用下面的方法来生成一个可以很容易适应的时间序列。
ts_data = ts(df$Booked, start = c(2017,1), end = c(2018,12), frequency = 12)
现在您可以简单地对此 ts_data
应用时间序列预测来预测 2019 年的值。我将剩下的代码留给您。谢谢!!
我需要有关以下查询的建议:"Based on your observations, what could you say about the load for the same months in year 2019?"
df 的 str()/head() 看起来像这样:
data.frame': 683 obs. of 10 variables:
$ Route : chr "A" "B" "A" "A" ...
$ FlightNumber: int 770 279 128 235 434 543 556 663 770 279 ...
$ Capacity : int 375 345 375 375 375 375 375 375 375 345 ...
$ Booked : int 379 314 374 379 373 377 379 378 379 294 ...
$ DDate : Date, format: "2018-05-01" "2018-05-01" "2018-05-02" "2018-05-03" ...
$ Year : num 2018 2018 2018 2018 2018 ...
$ Month : num 5 5 5 5 5 5 5 5 5 5 ...
$ Day : int 1 1 2 3 4 5 6 7 8 8 ...
$ Hour : int 12 20 12 12 12 12 12 12 12 20 ...
$ load : num 1.011 0.91 0.997 1.011 0.995 ...
Route FlightNumber Capacity Booked DDate Year Month Day Hour load(=Booked/Capacity)
1 A 770 375 379 2018-05-01 2018 5 1 12 1.0106667
2 B 279 345 314 2018-05-01 2018 5 1 20 0.9101449
3 A 128 375 374 2018-05-02 2018 5 2 12 0.9973333
4 A 235 375 379 2018-05-03 2018 5 3 12 1.0106667
5 A 434 375 373 2018-05-04 2018 5 4 12 0.9946667
6 A 543 375 377 2018-05-05 2018 5 5 12 1.0053333
如果我绘制数据,它看起来像这样:geom_point
更新:我最后做了以下事情:
dat_A <- test %>% select(Route, DDate, load) %>% filter(Route == "A")
ts_A <- ts(dat_A$load, start = c(2017,5), end = c(2018,11), frequency = 1*12)
forecast(ts_A, h=12) %>% plot()
Predicted outcome image
#Double checking
fit <- auto.arima(ts_A)
summary(fit)
predict <- forecast(fit,n=1)
plot(predict)
plot.ts(predict$residuals)
qqnorm(predict$residuals)
acf(predict$residuals)
预测靠谱吗?看起来相当平坦,尽管我也尝试通过 arima 进行 train(1:480)/validat(481:611) 然后以 RMSE 为 0.036 进行预测...
要将 vector
或 data.frame
转换为时间序列,您可以使用:
dat <- as.ts(as.matrix(dat))
您可以尝试以下解决方案。我可以指导您使用以下函数生成时间序列。首先加载你的数据说它是 df
并且它有列 Booked
所以你可以使用下面的方法来生成一个可以很容易适应的时间序列。
ts_data = ts(df$Booked, start = c(2017,1), end = c(2018,12), frequency = 12)
现在您可以简单地对此 ts_data
应用时间序列预测来预测 2019 年的值。我将剩下的代码留给您。谢谢!!