有谁知道为什么时间序列holt-winter模型建模预测之后,用accuracy算出的MAPE和公式代码算出的MAPE为什么不一样?
setwd("D:/发货数据")
library(readxl)
data <- read_excel("发货数据月份.xlsx")
View(data)
print(data,n=74)
##qty ord`
<dbl>
1 384000
2 737280
3 1347840
4 1470720
5 1106560
6 1025280
7 1105920
8 2035200
9 1424640
10 1378560
11 2296320
12 1132800
13 268800
14 944640
15 1113600
16 1175040
17 1501440
18 1751040
19 1351680
20 2622720
21 1559040
22 2895360
23 4404480
24 618240
25 15360
26 1259520
27 1198080
28 1539840
29 2154880
30 1390720
31 3256370
32 4212480
33 4661760
34 6964520
35 5859840
36 5664000
37 1958400
38 4446720
39 3175680
40 2039040
41 3955200
42 3141120
43 1071360
44 2138880
45 1109760
46 921600
47 3264000
48 1632000
49 1267200
50 2883840
51 3820800
52 4631040
53 5157120
54 2323200
55 3137280
56 4957440
57 4431360
58 4047360
59 5479200
60 506880
61 3901440
62 5940480
63 6604800
64 6374400
65 6869760
66 6120960
67 4638720
68 6094080
69 6451200
70 6607024
71 7153760
72 8392960
73 1098240
74 3141760
series<-ts(data,start=c(2018,2),frequency = 12)
series
## print(series)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
2018 384000 737280 1347840 1470720 1106560 1025280 1105920 2035200 1424640 1378560
2019 1132800 268800 944640 1113600 1175040 1501440 1751040 1351680 2622720 1559040 2895360
2020 618240 15360 1259520 1198080 1539840 2154880 1390720 3256370 4212480 4661760 6964520
2021 5664000 1958400 4446720 3175680 2039040 3955200 3141120 1071360 2138880 1109760 921600
2022 1632000 1267200 2883840 3820800 4631040 5157120 2323200 3137280 4957440 4431360 4047360
2023 506880 3901440 5940480 6604800 6374400 6869760 6120960 4638720 6094080 6451200 6607024
2024 8392960 1098240 3141760
Dec
2018 2296320
2019 4404480
2020 5859840
2021 3264000
2022 5479200
2023 7153760
2024
train<-ts(head(data,n=59),start=c(2018,2),frequency = 12)
train
trainhw<-HoltWinters(train,seasonal="additive",l.start=384000, b.start= 353280)
trainhw
trainhwforecast<-forecast(trainhw,h=12)
trainhwforecast
accuracy(trainhwforecast)
## ME RMSE MAE MPE MAPE MASE ACF1
Training set -183552.4 1147565 858237.9 -130.7332 157.1178 0.5107502 -0.05243135
difference <- data.frame (actual=c(506880, 3901440, 5940480, 6604800, 6374400, 6869760, 6120960, 4638720, 6094080, 6451200, 6607024, 7153760),
forecast=c(4302504,3517492,4278080, 4536428 , 4648536, 4943364, 5246032,5143367, 6188275, 5698303, 5793771,6826866 ))
#calculate MAPE
mean(abs((difference$actual-difference$forecast)/difference$actual)) * 100
##77.36225