-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFORECAST MODELS.R
More file actions
361 lines (293 loc) · 18.1 KB
/
Copy pathFORECAST MODELS.R
File metadata and controls
361 lines (293 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
remove.packages("rlang")
install.packages("rlang")
library("rlang")
install.packages("tseries")
library("tseries")
install.packages("forecast")
library("forecast")
install.packages("lubridate")
library("lubridate")
install.packages("moments")
library(moments)
library("ggplot2")
library(stats)
library("tsoutliers")
require(forecast)
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<PRE AND POST COVID-19<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
############## DAILY REVENUE -- PRE AND POST COVID-19 ###############################
data<- read.csv("C:/Users/Francesco/Downloads/fat_r000.csv", header=T) #Change here the dataset *******CHANGE RESTAURANT NUMBER HERE*******
#For all restaurants except R002 use these two rows
x<-data[-c(1677:1706) ,] #remove part from 3/4/2023
x<-x[-c(488:1218),] #remove part from 1/1/2020 to 31/12/2021
#For the restaurant R002 use these two rows instead of the previous two
#x<-data[-c(1244:1273) ,] #remove part from 3/4/2023 (FOR R002)
#x<-x[-c(55:785),] #remove part from 1/1/2020 to 31/12/2021 (FOR R002)
ts_R_raw <- ts(x$R000, start=1,frequency=7) #time series *******CHANGE RESTAURANT NUMBER HERE*******
ts_R <- tsclean(ts_R_raw) #cleaning of outliers
par(mfrow = c(2, 1)) #ACF and PACF
acf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
pacf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
print(Box.test(ts_R, type = "Ljung-Box"))
#+++++++++++++++++++++++++++++++ SARIMA +++++++++++++++++++++++++++++++++++
mod_R <-auto.arima(ts_R) #creation of the model
summary(mod_R)
arimafore_R <- forecast(mod_R, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "green4", main = " ",xlab = "Time [7 days]", ylab = "Daily revenue [€]")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
plot(arimafore_R, xlim = c(132,141), col = "green4",main = " ", xlab = "Time [7 days]", ylab = "Daily revenue [€]")
#in the previous "xlim" use:
#(132,141) for all restaurants except R002
#(71,79) for restaurant R002
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
y<-data[c(1677:1706) ,]$R000 #real values *******CHANGE RESTAURANT NUMBER HERE*******
#in the previous row use:
#(1677:1706) for all restaurants except R002
#(1244:1273) for restaurant R002
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
#++++++++++++++++++++++++++++++++++ TBATS ++++++++++++++++++++++++++++++++++++
mod_R_tbats <- tbats(ts_R) #creation of the model
summary(mod_R_tbats)
arimafore_R <- forecast(mod_R_tbats, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "green4", main = " ",xlab = "Time [7 days]", ylab = "Daily revenue [€]")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
plot(arimafore_R, xlim = c(132,141), col = "green4",main = " ", xlab = "Time [7 days]", ylab = "Daily revenue [€]")
#in the previous "xlim" use:
#(132,141) for all restaurants except R002
#(71,79) for restaurant R002
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
################DAILY RECEIPTS -- PRE AND POST COVID-19#############################
data<- read.csv("C:/Users/Francesco/Downloads/scon_r000.csv", header=T) #Change here the dataset *******CHANGE RESTAURANT NUMBER HERE*******
#For all restaurants except R002 use these two rows
x<-data[-c(1677:1706) ,] #remove part from 3/4/2023
x<-x[-c(488:1218),] #remove part from 1/1/2020 to 31/12/2021
#For the restaurant R002 use these two rows instead of the previous two
#x<-data[-c(1244:1273) ,] #remove part from 3/4/2023 (FOR R002)
#x<-x[-c(55:785),] #remove part from 1/1/2020 to 31/12/2021 (FOR R002)
ts_R_raw <- ts(x$R000, start=1,frequency=7) #time series *******CHANGE RESTAURANT NUMBER HERE*******
ts_R <- tsclean(ts_R_raw) #cleaning of outliers
par(mfrow = c(2, 1)) #ACF and PACF
acf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
pacf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
print(Box.test(ts_R, type = "Ljung-Box"))
#+++++++++++++++++++++++++++++++ SARIMA +++++++++++++++++++++++++++++++++++
mod_R <-auto.arima(ts_R) #creation of the model
summary(mod_R)
arimafore_R <- forecast(mod_R, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "blue", main = " ",xlab = "Time [7 days]", ylab = "Daily number of receipts")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
plot(arimafore_R, xlim = c(132,141), col = "blue",main = " ", xlab = "Time [7 days]", ylab = "Daily number of receipts")
#in the previous "xlim" use:
#(132,141) for all restaurants except R002
#(71,79) for restaurant R002
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
y<-data[c(1677:1706) ,]$R000 #real values *******CHANGE RESTAURANT NUMBER HERE*******
#in the previous row use:
#(1677:1706) for all restaurants except R002
#(1244:1273) for restaurant R002
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
#++++++++++++++++++++++++++++++++++ TBATS ++++++++++++++++++++++++++++++++++++
mod_R_tbats <- tbats(ts_R) #creation of the model
summary(mod_R_tbats)
arimafore_R <- forecast(mod_R_tbats, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "blue", main = " ",xlab = "Time [7 days]", ylab = "Daily number of receipts")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
plot(arimafore_R, xlim = c(132,141), col = "blue",main = " ", xlab = "Time [7 days]", ylab = "Daily number of receipts")
#in the previous "xlim" use:
#(132,141) for all restaurants except R002
#(71,79) for restaurant R002
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<POST COVID-19<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
############### DAILY REVENUE -- POST COVID-19 ###################################
data<- read.csv("C:/Users/Francesco/Downloads/fat_r000.csv", header=T) #Change here the dataset *******CHANGE RESTAURANT NUMBER HERE*******
#For all restaurants except R002 use the following row
x<-data[c(1219:1676) ,] #select only part after 1/1/2022
#For the restaurant R002 use the following row instead of the previous one
#x<-data[c(786:1243) ,] #select only part after 1/1/2022 (FOR R002)
ts_R_raw <- ts(x$R000, start=1,frequency=7) #time series *******CHANGE RESTAURANT NUMBER HERE*******
ts_R <- tsclean(ts_R_raw) #cleaning of outliers
par(mfrow = c(2, 1)) #ACF and PACF
acf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
pacf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
print(Box.test(ts_R, type = "Ljung-Box"))
#+++++++++++++++++++++++++++++++ SARIMA +++++++++++++++++++++++++++++++++++
mod_R <-auto.arima(ts_R) #creation of the model
summary(mod_R)
arimafore_R <- forecast(mod_R, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "green4", main = " ",xlab = "Time [7 days]", ylab = "Daily revenue [€]")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
plot(arimafore_R, xlim = c(63,72), col = "green4",main = " ", xlab = "Time [7 days]", ylab = "Daily revenue [€]")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
y<-data[c(1677:1706) ,]$R000 #real values *******CHANGE RESTAURANT NUMBER HERE*******
#in the previous row use:
#(1677:1706) for all restaurants except R002
#(1244:1273) for restaurant R002
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
#++++++++++++++++++++++++++++++++++ TBATS ++++++++++++++++++++++++++++++++++++
mod_R_tbats <- tbats(ts_R) #creation of the model
summary(mod_R_tbats)
arimafore_R <- forecast(mod_R_tbats, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "green4", main = " ",xlab = "Time [7 days]", ylab = "Daily revenue [€]")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
plot(arimafore_R, xlim = c(63,72), col = "green4",main = " ", xlab = "Time [7 days]", ylab = "Daily revenue [€]")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
################DAILY RECEIPTS -- POST COVID-19 ##################################
data<- read.csv("C:/Users/Francesco/Downloads/scon_r000.csv", header=T) #Change here the dataset *******CHANGE RESTAURANT NUMBER HERE*******
#For all restaurants except R002 use the following row
x<-data[c(1219:1676) ,] #select only part after 1/1/2022
#For the restaurant R002 use the following row instead of the previous one
#x<-data[c(786:1243) ,] #select only part after 1/1/2022 (FOR R002)
ts_R_raw <- ts(x$R000, start=1,frequency=7) #time series *******CHANGE RESTAURANT NUMBER HERE*******
ts_R <- tsclean(ts_R_raw) #cleaning of outliers
par(mfrow = c(2, 1)) #ACF and PACF
acf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
pacf(ts_R, col = "purple", lwd = 4, ci.col = "red", main = "")
print(Box.test(ts_R, type = "Ljung-Box"))
#+++++++++++++++++++++++++++++++ SARIMA +++++++++++++++++++++++++++++++++++
mod_R <-auto.arima(ts_R) #creation of the model
summary(mod_R)
arimafore_R <- forecast(mod_R, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "blue", main = " ",xlab = "Time [7 days]", ylab = "Daily number of receipts")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R000$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
plot(arimafore_R, xlim = c(63,72), col = "blue",main = " ", xlab = "Time [7 days]", ylab = "Daily number of receipts")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "moccasin",border = NA)
lines(arimafore_R$mean, col = "red", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
y<-data[c(1677:1706) ,]$R000 #real values *******CHANGE RESTAURANT NUMBER HERE*******
#in the previous row use:
#(1677:1706) for all restaurants except R002
#(1244:1273) for restaurant R002
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE
#++++++++++++++++++++++++++++++++++ TBATS ++++++++++++++++++++++++++++++++++++
mod_R_tbats <- tbats(ts_R) #creation of the model
summary(mod_R_tbats)
arimafore_R <- forecast(mod_R_tbats, h=30, level=95) #forecast at 30 days
par(mfrow=c(2,1)) #plot of time series and forecast
plot(arimafore_R, col = "blue", main = " ",xlab = "Time [7 days]", ylab = "Daily number of receipts")
polygon(c(time(arimafore_R$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
plot(arimafore_R, xlim = c(63,72), col = "blue",main = " ", xlab = "Time [7 days]", ylab = "Daily number of receipts")
polygon(c(time(arimafore_R000$lower), rev(time(arimafore_R$upper))),c(arimafore_R$lower, rev(arimafore_R$upper)),col = "lightcyan1",border = NA)
lines(arimafore_R$mean, col = "purple", lwd = 2)
shapiro.test(mod_R$residuals) #Study of residuals
par(mfrow = c(1, 2))
qqnorm(mod_R$residuals, pch = 1, frame = FALSE)
qqline(mod_R$residuals, col = "green3", lwd = 3)
residui <- mod_R$residuals
residui_standardizzati <- (residui - mean(residui)) / sd(residui)
hist(residui_standardizzati, breaks = 15, probability = TRUE, col = "rosybrown1", main = " ",xlab = "standardalized residuals")
curve(dnorm(x, mean = mean(residui_standardizzati), sd = sd(residui_standardizzati)),col = "blue", lwd = 3, add = TRUE)
w<-as.numeric(arimafore_R$mean) #forecasted values
non_zero_indices <- y != 0
w_n <- w[non_zero_indices]
y_n <- y[non_zero_indices]
print(mean(abs(w_n - y_n) / y_n)) #calculation of MAPE