Train Individual Models

train_models(
  run_info,
  run_global_models = FALSE,
  run_local_models = TRUE,
  global_model_recipes = c("R1"),
  feature_selection = FALSE,
  negative_forecast = FALSE,
  parallel_processing = NULL,
  inner_parallel = FALSE,
  num_cores = NULL,
  seed = 123,
  debug = FALSE
)

Arguments

run_info

run info using the set_run_info() function

run_global_models

If TRUE, run multivariate models on the entire data set (across all time series) as a global model. Can be override by models_not_to_run. Default of NULL runs global models for all date types except week and day.

run_local_models

If TRUE, run models by individual time series as local models.

global_model_recipes

Recipes to use in global models.

feature_selection

Implement feature selection before model training. This requires the optional Boruta, corrr, ranger, and vip packages. vip is available from https://bgreenwell.r-universe.dev and requires R 4.1 or newer.

negative_forecast

If TRUE, allow forecasts to dip below zero.

parallel_processing

Default of NULL runs no parallel processing and forecasts each individual time series one after another. 'local_machine' leverages all cores on current machine Finn is running on. 'spark' runs time series in parallel on a spark cluster in Azure Databricks or Azure Synapse.

inner_parallel

Run components of forecast process inside a specific time series in parallel. Can only be used if parallel_processing is set to NULL or 'spark'.

num_cores

Number of cores to run when parallel processing is set up. Used when running parallel computations on local machine or within Azure. Default of NULL uses total amount of cores on machine minus one. Can't be greater than number of cores on machine minus 1.

seed

Set seed for random number generator. Numeric value.

debug

If TRUE, will stop on errors and show traceback.

Value

trained model outputs are written to disk.

Details

Ordinary calls retain the saved-training reuse checks. When invoked by forecast-update recovery for an unusable accepted default result, model fitting may be repeated despite an existing training log. Preparation and output formats are unchanged; the recovery control is internal and is not saved in the run log.

Selected experimental custom models use the pinned enrollment from prep_models(). They run only in declared enabled local/global modes, execute before built-in candidates within each mode, bypass tuning, and retain chronological analysis-fold isolation. Custom source/dependency failures and missing fold predictions are hard errors, including in mixed pools. Required predictors and finite historical targets must remain available. No source regeneration or dependency installation occurs. Custom Model_Name retains its alias; Model_ID begins with custom- and the full version hash, followed by model type and recipe. Saved workflows, fits and forecasts must match the pinned pool before reuse. Custom models train on the untransformed C1 recipe, so stationary and Box-Cox inverse steps are skipped for them and feature selection applies only to built-in models. Global custom models always use C1 regardless of global_model_recipes. Sequential, local_machine, spark and inner_parallel execution are supported. negative_forecast = FALSE floors custom forecasts at zero, as for built-in models. Existing built-in-only behavior is unchanged. Temporal custom definitions evaluate complete horizons from existing predictor rows during resampling, then retain only the original scoring rows. Analysis cutoffs, scored targets and selection rules do not change.

Reviewed custom hierarchy runs additionally require run_local_models = TRUE and run_global_models = FALSE. Each prepared hierarchy node is fitted independently under the same explicitly enrolled mixed pool. These are base forecasts; final_models() applies normal reconciliation to the bottom level. Missing or changed topology, inputs, approval or candidate artifacts cannot be treated as successful saved results.

Examples

# \donttest{
data_tbl <- timetk::m4_monthly %>%
  dplyr::rename(Date = date) %>%
  dplyr::mutate(id = as.character(id)) %>%
  dplyr::filter(
    Date >= "2013-01-01",
    Date <= "2015-06-01"
  )

run_info <- set_run_info()
#> Finn Submission Info
#> • Project Name: finn_project
#> • Run Name: finn_fcst-20261020T013508Z
#> 

prep_data(run_info,
  input_data = data_tbl,
  combo_variables = c("id"),
  target_variable = "value",
  date_type = "month",
  forecast_horizon = 3
)
#> ℹ Prepping Data
#> ✔ Prepping Data [2.9s]
#> 

prep_models(run_info,
  models_to_run = c("arima", "glmnet"),
  num_hyperparameters = 2,
  back_test_scenarios = 6,
  run_ensemble_models = FALSE
)
#> ℹ Creating Model Workflows
#> ✔ Creating Model Workflows [164ms]
#> 
#> ℹ Creating Model Hyperparameters
#> ✔ Creating Model Hyperparameters [169ms]
#> 
#> ℹ Creating Train Test Splits
#> ✔ Creating Train Test Splits [225ms]
#> 

train_models(run_info)
#> ℹ Training Individual Models
#> ✔ Training Individual Models [36.8s]
#> 
# }