LOAD PACKAGES
library(tsibble)
library(fable.prophet)
library(tidyverse)
library(lubridate)
library(skimr)
library(DT)
options(scipen=999)
READ IN DATA
lax_passengers <- read.csv("https://raw.githubusercontent.com/mitchelloharawild/fable.prophet/master/data-raw/lax_passengers.csv")
skim(lax_passengers)
Data summary
| Name |
lax_passengers |
| Number of rows |
5870 |
| Number of columns |
6 |
| _______________________ |
|
| Column type frequency: |
|
| factor |
5 |
| numeric |
1 |
| ________________________ |
|
| Group variables |
None |
Variable type: factor
| DataExtractDate |
0 |
1 |
FALSE |
60 |
05/: 3630, 07/: 73, 03/: 39, 05/: 39 |
| ReportPeriod |
0 |
1 |
FALSE |
159 |
04/: 40, 01/: 39, 02/: 39, 03/: 39 |
| Terminal |
0 |
1 |
FALSE |
11 |
Ter: 636, Ter: 636, Ter: 636, Ter: 635 |
| Arrival_Departure |
0 |
1 |
FALSE |
2 |
Dep: 2978, Arr: 2892 |
| Domestic_International |
0 |
1 |
FALSE |
2 |
Dom: 3176, Int: 2694 |
Variable type: numeric
| Passenger_Count |
0 |
1 |
154971.5 |
153557 |
1 |
19674.25 |
105149 |
270988.5 |
889348 |
▇▃▂▁▁ |
TIDY AND SUMMARIZE DATA THEN CONVERT TO TSIBBLE
lax_passengers <- lax_passengers %>%
mutate(datetime = mdy_hms(ReportPeriod)) %>%
group_by(month = yearmonth(datetime), type = Domestic_International) %>%
summarise(passengers = sum(Passenger_Count)) %>%
ungroup()
lax_passengers <- as_tsibble(lax_passengers, index = month, key = type)
EDA
TIMESERIES PLOT
lax_passengers %>%
autoplot(passengers)

MODELING
## Warning: `data_frame()` is deprecated as of tibble 1.1.0.
## Please use `tibble()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: `as_data_frame()` is deprecated as of tibble 2.0.0.
## Please use `as_tibble()` instead.
## The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## # A mable: 2 x 2
## # Key: type [2]
## type mdl
## <fct> <model>
## 1 Domestic <prophet>
## 2 International <prophet>
MODEL DECOMPOSITION

MODEL SEASONALITY

FORECASTING
## # A fable: 72 x 5 [1M]
## # Key: type, .model [2]
## type .model month passengers .mean
## <fct> <chr> <mth> <dist> <dbl>
## 1 Domestic mdl 2019 Apr sample[1000] 5214138.
## 2 Domestic mdl 2019 May sample[1000] 5492255.
## 3 Domestic mdl 2019 Jun sample[1000] 5809360.
## 4 Domestic mdl 2019 Jul sample[1000] 6152372.
## 5 Domestic mdl 2019 Aug sample[1000] 5989077.
## 6 Domestic mdl 2019 Sep sample[1000] 4995836.
## 7 Domestic mdl 2019 Oct sample[1000] 5340026.
## 8 Domestic mdl 2019 Nov sample[1000] 5134207.
## 9 Domestic mdl 2019 Dec sample[1000] 5316517.
## 10 Domestic mdl 2020 Jan sample[1000] 4869931.
## # ... with 62 more rows
fc %>%
autoplot(lax_passengers)

#> Called from: hilo.fbl_ts(object, level = level)
#> debug at /home/mitchell/github/fabletools/R/fable.R#187: as_tsibble(x) %>% mutate(!!!set_names(map(level, function(.x) expr(hilo(!!sym(distribution_var(x)),
#> !!.x))), paste0(level, "%")))
EVALUATE Accuracy
accuracy(fit)
## # A tibble: 2 x 10
## type .model .type ME RMSE MAE MPE MAPE MASE ACF1
## <fct> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Domestic mdl Traini~ -245. 77532. 62366. -0.0689 1.57 0.344 0.442
## 2 Internation~ mdl Traini~ 205. 46382. 34866. -0.0668 2.26 0.357 0.730