knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE ) library(finnts)
The easiest way to use the finnts package is through the function forecast_time_series()
, but instead of calling that function you can also call the sub components of the Finn forecast process. This could enable you to break out your time series forecast process into separate steps in a production pipeline, or even give you more control over how you use Finn.
Below is an example workflow of using the sub components of Finn.
Let's get some example data and then set our Finn run info.
library(finnts) hist_data <- timetk::m4_monthly %>% dplyr::filter( date >= "2013-01-01", id == "M2" ) %>% dplyr::rename(Date = date) %>% dplyr::mutate(id = as.character(id)) run_info <- set_run_info( experiment_name = "finnts_fcst", run_name = "finn_sub_component_run" )
Clean and prepare our data before training models. We can even pull out our prepped data to see the features and transformations applied before models are trained.
prep_data( run_info = run_info, input_data = hist_data, combo_variables = c("id"), target_variable = "value", date_type = "month", forecast_horizon = 6 ) R1_prepped_data_tbl <- get_prepped_data( run_info = run_info, recipe = "R1" ) print(R1_prepped_data_tbl) R2_prepped_data_tbl <- get_prepped_data( run_info = run_info, recipe = "R2" ) print(R2_prepped_data_tbl)
Now that our data is prepared for modeling, let's now train some models. First we need to create the model workflows, determine our back testing process, and how many hyperparameter combinations to try during the validation process.
Then we can kick off training each model on our data.
prep_models( run_info = run_info, models_to_run = c("arima", "ets", "glmnet"), num_hyperparameters = 2 ) train_models( run_info = run_info, run_global_models = FALSE )
After each individual model is trained, we can feed those predictions into ensemble models.
ensemble_models(run_info = run_info)
The last step is to create the final simple model averages and select the best models.
final_models(run_info = run_info)
Finally we can now retrieve the forecast results from this Finn run.
finn_output_tbl <- get_forecast_data(run_info = run_info) print(finn_output_tbl)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.