Skip to content

Commit

Permalink
doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
mitokic committed Apr 24, 2024
1 parent fda57df commit 9da5a2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion man/prep_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 38 additions & 26 deletions vignettes/feature-engineering.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,40 @@ Polynomial transformations are created for the target variable, and lags are the

In addition to the standard approaches above, finnts also does two different ways of preparing features to be created for a multivariate machine learning model.

In the first recipe, referred to as "R1" in default finnts models, by default takes a multistep horizon approach. Meaning it will create features that can be used by specific multivariate models that optimize for each period in a forecast horizon. More on this in the "models used in finnts" vignette. If `multistep_horizon` is FALSE in `prep_models()`, all of the engineered target and external regressor features are used but the lags cannot be less than the forecast horizon. For example, a monthly data set with a forecast horizon of 3, finnts will take engineered features like lags and rolling window features but only use those lags that are for periods equal to or greater than 3. Recursive forecasting is not supported in finnts multivariate machine learning models, since feeding forecast outputs as features to create another forecast adds complex layers of uncertainty that can easily spiral out of control and produce poor forecasts. NA values created by generating lag features are filled "up". This results in the first initial periods of a time series having some data leakage but the effect should be small if the time series is long enough.
In the first recipe, referred to as "R1" in default finnts models, by default takes a single step horizon approach. Meaning all of the engineered target and external regressor features are used but the lags cannot be less than the forecast horizon. For example, a monthly data set with a forecast horizon of 3, finnts will take engineered features like lags and rolling window features but only use those lags that are for periods equal to or greater than 3. You can also run a multistep horizon approach by setting `multistep_horizon` to TRUE in `prep_models()`. The multistep approach will create features that can be used by specific multivariate models that optimize for each period in a forecast horizon. More on this in the "models used in finnts" vignette. Recursive forecasting is not supported in finnts multivariate machine learning models, since feeding forecast outputs as features to create another forecast adds complex layers of uncertainty that can easily spiral out of control and produce poor forecasts. NA values created by generating lag features are filled "up". This results in the first initial periods of a time series having some data leakage but the effect should be small if the time series is long enough.

```{r, message = FALSE}
library(finnts)
hist_data <- timetk::m4_monthly %>%
dplyr::filter(date >= "2012-01-01",
id == "M2") %>%
dplyr::filter(
date >= "2012-01-01",
id == "M2"
) %>%
dplyr::rename(Date = date) %>%
dplyr::mutate(id = as.character(id))
run_info <- set_run_info(
experiment_name = "finnts_fcst",
experiment_name = "finnts_fcst",
run_name = "R1_run"
)
prep_data(run_info = run_info,
input_data = hist_data,
combo_variables = c("id"),
target_variable = "value",
date_type = "month",
forecast_horizon = 3,
recipes_to_run = "R1",
multistep_horizon = TRUE)
prep_data(
run_info = run_info,
input_data = hist_data,
combo_variables = c("id"),
target_variable = "value",
date_type = "month",
forecast_horizon = 3,
recipes_to_run = "R1",
multistep_horizon = FALSE
)
R1_prepped_data_tbl <- get_prepped_data(run_info = run_info,
recipe = "R1")
R1_prepped_data_tbl <- get_prepped_data(
run_info = run_info,
recipe = "R1"
)
print(R1_prepped_data_tbl)
```
Expand All @@ -110,26 +116,32 @@ The second recipe is referred to as "R2" in default finnts models. It takes a ve
library(finnts)
hist_data <- timetk::m4_monthly %>%
dplyr::filter(date >= "2012-01-01",
id == "M2") %>%
dplyr::filter(
date >= "2012-01-01",
id == "M2"
) %>%
dplyr::rename(Date = date) %>%
dplyr::mutate(id = as.character(id))
run_info <- set_run_info(
experiment_name = "finnts_fcst",
experiment_name = "finnts_fcst",
run_name = "R2_run"
)
prep_data(run_info = run_info,
input_data = hist_data,
combo_variables = c("id"),
target_variable = "value",
date_type = "month",
forecast_horizon = 3,
recipes_to_run = "R2")
prep_data(
run_info = run_info,
input_data = hist_data,
combo_variables = c("id"),
target_variable = "value",
date_type = "month",
forecast_horizon = 3,
recipes_to_run = "R2"
)
R2_prepped_data_tbl <- get_prepped_data(run_info = run_info,
recipe = "R2")
R2_prepped_data_tbl <- get_prepped_data(
run_info = run_info,
recipe = "R2"
)
print(R2_prepped_data_tbl)
```
Expand Down

0 comments on commit 9da5a2c

Please sign in to comment.