Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created February 21, 2022 12:19
Show Gist options
  • Select an option

  • Save MJacobs1985/55dd31b2bb197913efeff6dfaff1ad6d to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/55dd31b2bb197913efeff6dfaff1ad6d to your computer and use it in GitHub Desktop.
master_data_tbl <- dfnew %>%
filter(date_interval>"2021-06-10")%>%
dplyr::select(feed_provided,
lcn_id,
newField,
date_interval)%>%
filter(!is.na(date_interval))%>%
distinct()%>%
group_by(lcn_id, newField) %>%
filter(n() >= 30)%>%
imputeTS::na_kalman(.)%>%
as_tsibble(key = c(lcn_id,newField),
index = date_interval)
train_tbl <- master_data_tbl%>%filter_index(. ~ "2021-11-15")
test_tbl <- master_data_tbl%>%filter_index("2021-11-15" ~ .)
fpp3_model_table <- train_tbl %>%
model(
naive_mod = NAIVE(feed_provided + 1),
snaive_mod = SNAIVE(feed_provided + 1),
drift_mod = RW(feed_provided + 1 ~ drift()),
ses_mod = ETS(feed_provided + 1 ~ error("A") + trend("N") + season("N"), opt_crit = "mse"),
hl_mod = ETS(feed_provided + 1 ~ error("A") + trend("A") + season("N"), opt_crit = "mse"),
hldamp_mod = ETS(feed_provided + 1 ~ error("A") + trend("Ad") + season("N"), opt_crit = "mse"),
arima_mod = ARIMA(feed_provided + 1),
dhr_mod = ARIMA(feed_provided + 1 ~ PDQ(0,0,0) + fourier(K=2)),
tslm_mod = TSLM(feed_provided + 1 ~ 1),
crost_mod = CROSTON(feed_provided + 1),
sba_mod = CROSTON(feed_provided + 1, type = "sba")) %>%
mutate(ensemble_sm_mod = combination_ensemble(arima_mod,
ses_mod,
crost_mod, sba_mod))
fpp3_model_table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment