prophet_boost: General Interface for Boosted PROPHET Time Series Models

Description Usage Arguments Details Engine Details Fit Details See Also Examples

View source: R/parsnip-prophet_boost.R

Description

prophet_boost() is a way to generate a specification of a Boosted PROPHET model before fitting and allows the model to be created using different packages. Currently the only package is prophet.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
prophet_boost(
  mode = "regression",
  growth = NULL,
  changepoint_num = NULL,
  changepoint_range = NULL,
  seasonality_yearly = NULL,
  seasonality_weekly = NULL,
  seasonality_daily = NULL,
  season = NULL,
  prior_scale_changepoints = NULL,
  prior_scale_seasonality = NULL,
  prior_scale_holidays = NULL,
  logistic_cap = NULL,
  logistic_floor = NULL,
  mtry = NULL,
  trees = NULL,
  min_n = NULL,
  tree_depth = NULL,
  learn_rate = NULL,
  loss_reduction = NULL,
  sample_size = NULL,
  stop_iter = NULL
)

Arguments

mode

A single character string for the type of model. The only possible value for this model is "regression".

growth

String 'linear' or 'logistic' to specify a linear or logistic trend.

changepoint_num

Number of potential changepoints to include for modeling trend.

changepoint_range

Adjusts the flexibility of the trend component by limiting to a percentage of data before the end of the time series. 0.80 means that a changepoint cannot exist after the first 80% of the data.

seasonality_yearly

One of "auto", TRUE or FALSE. Toggles on/off a seasonal component that models year-over-year seasonality.

seasonality_weekly

One of "auto", TRUE or FALSE. Toggles on/off a seasonal component that models week-over-week seasonality.

seasonality_daily

One of "auto", TRUE or FALSE. Toggles on/off a seasonal componet that models day-over-day seasonality.

season

'additive' (default) or 'multiplicative'.

prior_scale_changepoints

Parameter modulating the flexibility of the automatic changepoint selection. Large values will allow many changepoints, small values will allow few changepoints.

prior_scale_seasonality

Parameter modulating the strength of the seasonality model. Larger values allow the model to fit larger seasonal fluctuations, smaller values dampen the seasonality.

prior_scale_holidays

Parameter modulating the strength of the holiday components model, unless overridden in the holidays input.

logistic_cap

When growth is logistic, the upper-bound for "saturation".

logistic_floor

When growth is logistic, the lower-bound for "saturation".

mtry

A number for the number (or proportion) of predictors that will be randomly sampled at each split when creating the tree models (xgboost only).

trees

An integer for the number of trees contained in the ensemble.

min_n

An integer for the minimum number of data points in a node that is required for the node to be split further.

tree_depth

An integer for the maximum depth of the tree (i.e. number of splits) (xgboost only).

learn_rate

A number for the rate at which the boosting algorithm adapts from iteration-to-iteration (xgboost only).

loss_reduction

A number for the reduction in the loss function required to split further (xgboost only).

sample_size

number for the number (or proportion) of data that is exposed to the fitting routine.

stop_iter

The number of iterations without improvement before stopping (xgboost only).

Details

The data given to the function are not saved and are only used to determine the mode of the model. For prophet_boost(), the mode will always be "regression".

The model can be created using the fit() function using the following engines:

Main Arguments

The main arguments (tuning parameters) for the PROPHET model are:

The main arguments (tuning parameters) for the model XGBoost model are:

These arguments are converted to their specific names at the time that the model is fit.

Other options and argument can be set using set_engine() (See Engine Details below).

If parameters need to be modified, update() can be used in lieu of recreating the object from scratch.

Engine Details

The standardized parameter names in modeltime can be mapped to their original names in each engine:

Model 1: PROPHET:

modeltime prophet
growth growth ('linear')
changepoint_num n.changepoints (25)
changepoint_range changepoints.range (0.8)
seasonality_yearly yearly.seasonality ('auto')
seasonality_weekly weekly.seasonality ('auto')
seasonality_daily daily.seasonality ('auto')
season seasonality.mode ('additive')
prior_scale_changepoints changepoint.prior.scale (0.05)
prior_scale_seasonality seasonality.prior.scale (10)
prior_scale_holidays holidays.prior.scale (10)
logistic_cap df$cap (NULL)
logistic_floor df$floor (NULL)

Model 2: XGBoost:

modeltime xgboost::xgb.train
tree_depth max_depth (6)
trees nrounds (15)
learn_rate eta (0.3)
mtry colsample_bynode (1)
min_n min_child_weight (1)
loss_reduction gamma (0)
sample_size subsample (1)
stop_iter early_stop

Other options can be set using set_engine().

prophet_xgboost

Model 1: PROPHET (prophet::prophet):

1
2
3
4
5
6
## function (df = NULL, growth = "linear", changepoints = NULL, n.changepoints = 25, 
##     changepoint.range = 0.8, yearly.seasonality = "auto", weekly.seasonality = "auto", 
##     daily.seasonality = "auto", holidays = NULL, seasonality.mode = "additive", 
##     seasonality.prior.scale = 10, holidays.prior.scale = 10, changepoint.prior.scale = 0.05, 
##     mcmc.samples = 0, interval.width = 0.8, uncertainty.samples = 1000, 
##     fit = TRUE, ...)

Parameter Notes:

Logistic Growth and Saturation Levels:

Limitations:

Model 2: XGBoost (xgboost::xgb.train):

1
2
3
4
## function (params = list(), data, nrounds, watchlist = list(), obj = NULL, 
##     feval = NULL, verbose = 1, print_every_n = 1L, early_stopping_rounds = NULL, 
##     maximize = NULL, save_period = NULL, save_name = "xgboost.model", xgb_model = NULL, 
##     callbacks = list(), ...)

Parameter Notes:

Fit Details

Date and Date-Time Variable

It's a requirement to have a date or date-time variable as a predictor. The fit() interface accepts date and date-time features and handles them internally.

Univariate (No Extra Regressors):

For univariate analysis, you must include a date or date-time feature. Simply use:

Multivariate (Extra Regressors)

Extra Regressors parameter is populated using the fit() or fit_xy() function:

Xreg Example: Suppose you have 3 features:

  1. y (target)

  2. date (time stamp),

  3. month.lbl (labeled month as a ordered factor).

The month.lbl is an exogenous regressor that can be passed to the arima_reg() using fit():

Note that date or date-time class values are excluded from xreg.

See Also

fit.model_spec(), set_engine()

Examples

 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
library(dplyr)
library(lubridate)
library(parsnip)
library(rsample)
library(timetk)
library(modeltime)

# Data
m750 <- m4_monthly %>% filter(id == "M750")
m750

# Split Data 80/20
splits <- initial_time_split(m750, prop = 0.8)

# ---- PROPHET ----

# Model Spec
model_spec <- prophet_boost(
    learn_rate = 0.1
) %>%
    set_engine("prophet_xgboost")

# Fit Spec
## Not run: 
model_fit <- model_spec %>%
    fit(log(value) ~ date + as.numeric(date) + month(date, label = TRUE),
        data = training(splits))
model_fit

## End(Not run)

modeltime documentation built on July 16, 2021, 9:08 a.m.