Skip to content

Commit

Permalink
adjust how many sub models are built for each date type
Browse files Browse the repository at this point in the history
  • Loading branch information
mitokic committed Apr 24, 2024
1 parent a1417b3 commit fda57df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
9 changes: 9 additions & 0 deletions R/prep_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,16 @@ get_lag_periods <- function(lag_periods,
"day" = c(7, 14, 21, 28, 60, 90, 180, 365)
)

# change multistep horizons to run based on date type
if (multistep_horizon) {
if (date_type == "day") {
oplist <- c(28, 90, 180)
} else if (date_type == "week") {
oplist <- c(4, 12, 24)
} else if (date_type == "month") {
c(1, 2, 3, 6, 12)
}

if (max(oplist) < forecast_horizon) {
lag_periods <- c(oplist, forecast_horizon)
} else {
Expand Down
21 changes: 13 additions & 8 deletions tests/testthat/test-multistep_horizon.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ test_that("multistep_horizon yearly data", {
back_test_scenarios = 4,
models_to_run = "xgboost",
run_ensemble_models = FALSE,
num_hyperparameters = 1
num_hyperparameters = 1,
pca = TRUE
)

# train models
Expand Down Expand Up @@ -69,7 +70,8 @@ test_that("multistep_horizon quarterly data", {
back_test_scenarios = 6,
models_to_run = "mars",
run_ensemble_models = FALSE,
num_hyperparameters = 1
num_hyperparameters = 1,
pca = TRUE
)

# train models
Expand Down Expand Up @@ -118,7 +120,8 @@ test_that("multistep_horizon monthly data", {
back_test_scenarios = 2,
models_to_run = "cubist",
run_ensemble_models = FALSE,
num_hyperparameters = 1
num_hyperparameters = 1,
pca = TRUE
)

# train models
Expand Down Expand Up @@ -164,7 +167,8 @@ test_that("multistep_horizon weekly data", {
back_test_scenarios = 4,
models_to_run = "glmnet",
run_ensemble_models = FALSE,
num_hyperparameters = 1
num_hyperparameters = 1,
pca = TRUE
)

# train models
Expand All @@ -177,7 +181,7 @@ test_that("multistep_horizon weekly data", {
model_length <- length(workflow_tbl$Model_Fit[[1]]$fit$fit$fit$models)

# Assertions
expect_equal(model_length, 4)
expect_equal(model_length, 1)
})

test_that("multistep_horizon daily data", {
Expand All @@ -200,7 +204,7 @@ test_that("multistep_horizon daily data", {
combo_variables = c("id"),
target_variable = "value",
date_type = "day",
forecast_horizon = 28,
forecast_horizon = 30,
recipes_to_run = "R1",
multistep_horizon = TRUE
)
Expand All @@ -211,7 +215,8 @@ test_that("multistep_horizon daily data", {
back_test_spacing = 7,
models_to_run = "glmnet",
run_ensemble_models = FALSE,
num_hyperparameters = 1
num_hyperparameters = 1,
pca = TRUE
)

# train models
Expand All @@ -224,5 +229,5 @@ test_that("multistep_horizon daily data", {
model_length <- length(workflow_tbl$Model_Fit[[1]]$fit$fit$fit$models)

# Assertions
expect_equal(model_length, 4)
expect_equal(model_length, 2)
})

0 comments on commit fda57df

Please sign in to comment.