knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", warning = FALSE )
r as.character(packageVersion("gts"))
The goal of gts
is to speed up the functionality provided by fable
.
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("markfairbanks/gts")
gts
has 3 core functions:
ts_prep()
: Convert a data frame to a gts
ready datasetts_split()
: Split your dataset to quickly enable parallel processingts_unnest_fable()
: Unnest a fable columnStarting with some example data:
library(gts) library(fpp3) library(tidyverse) aus_df <- tsibbledata::aus_livestock %>% rename_all(janitor::make_clean_names) %>% filter(state == "Australian Capital Territory") %>% mutate(month = as_date(month)) head(aus_df)
You can then use this to prep your data and create models
aus_ts <- aus_df %>% ts_prep(key = c(animal, state), index = month, target = count) %>% mutate(mable = map(time_series, model, ets = ETS(count))) aus_ts
You can create forecasts from here, or get model accuracy.
aus_ts <- aus_ts %>% mutate(fable = map(mable, forecast, h = 1), accuracy = map(mable, accuracy)) aus_ts
You can unnest the fable as follows:
aus_ts %>% ts_unnest_fable(fable)
pacman::p_load(furrr) model_fn <- function(.data) { .data %>% mutate(mable = map(time_series, model, ets = ETS(count)), fable = map(mable, forecast, h = 1), accuracy = map(mable, accuracy)) } plan(multiprocess) parallel_ts <- aus_df %>% ts_prep(key = c(animal, state), index = month, target = count) %>% ts_split(6) %>% future_map_dfr(model_fn) future:::ClusterRegistry("stop")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.