View source: R/parsnip-naive_reg.R
naive_reg | R Documentation |
naive_reg()
is a way to generate a specification of an NAIVE or SNAIVE model
before fitting and allows the model to be created using
different packages.
naive_reg(mode = "regression", id = NULL, seasonal_period = NULL)
mode |
A single character string for the type of model. The only possible value for this model is "regression". |
id |
An optional quoted column name (e.g. "id") for identifying multiple time series (i.e. panel data). |
seasonal_period |
SNAIVE only. A seasonal frequency. Uses "auto" by default. A character phrase of "auto" or time-based phrase of "2 weeks" can be used if a date or date-time variable is provided. See Fit Details below. |
The data given to the function are not saved and are only used
to determine the mode of the model. For naive_reg()
, the
mode will always be "regression".
The model can be created using the fit()
function using the
following engines:
"naive" (default) - Performs a NAIVE forecast
"snaive" - Performs a Seasonal NAIVE forecast
naive (default engine)
The engine uses naive_fit_impl()
The NAIVE implementation uses the last observation and forecasts this value forward.
The id
can be used to distinguish multiple time series contained in
the data
The seasonal_period
is not used but provided for consistency with the SNAIVE
implementation
snaive (default engine)
The engine uses snaive_fit_impl()
The SNAIVE implementation uses the last seasonal series in the data and forecasts this sequence of observations forward
The id
can be used to distinguish multiple time series contained in
the data
The seasonal_period
is used to determine how far back to define the repeated
series. This can be a numeric value (e.g. 28) or a period (e.g. "1 month")
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.
fit(y ~ date)
ID features (Multiple Time Series, Panel Data)
The id
parameter is populated using the fit()
or fit_xy()
function:
ID Example: Suppose you have 3 features:
y
(target)
date
(time stamp),
series_id
(a unique identifer that identifies each time series in your data).
The series_id
can be passed to the naive_reg()
using
fit()
:
naive_reg(id = "series_id")
specifes that the series_id
column should be used
to identify each time series.
fit(y ~ date + series_id)
will pass series_id
on to the underlying
naive or snaive functions.
Seasonal Period Specification (snaive)
The period can be non-seasonal (seasonal_period = 1 or "none"
) or
yearly seasonal (e.g. For monthly time stamps, seasonal_period = 12
, seasonal_period = "12 months"
, or seasonal_period = "yearly"
).
There are 3 ways to specify:
seasonal_period = "auto"
: A seasonal period is selected based on the periodicity of the data (e.g. 12 if monthly)
seasonal_period = 12
: A numeric frequency. For example, 12 is common for monthly data
seasonal_period = "1 year"
: A time-based phrase. For example, "1 year" would convert to 12 for monthly data.
External Regressors (Xregs)
These models are univariate. No xregs are used in the modeling process.
fit.model_spec()
, set_engine()
library(dplyr)
library(parsnip)
library(rsample)
library(timetk)
# Data
m750 <- m4_monthly %>% filter(id == "M750")
m750
# Split Data 80/20
splits <- initial_time_split(m750, prop = 0.8)
# ---- NAIVE ----
# Model Spec
model_spec <- naive_reg() %>%
set_engine("naive")
# Fit Spec
model_fit <- model_spec %>%
fit(log(value) ~ date, data = training(splits))
model_fit
# ---- SEASONAL NAIVE ----
# Model Spec
model_spec <- naive_reg(
id = "id",
seasonal_period = 12
) %>%
set_engine("snaive")
# Fit Spec
model_fit <- model_spec %>%
fit(log(value) ~ date + id, data = training(splits))
model_fit
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.