Skip to content

Commit

Permalink
Merge pull request #143 from microsoft/mitokic/08252023/hts-recon-error
Browse files Browse the repository at this point in the history
Mitokic/08252023/hts recon error
  • Loading branch information
mitokic authored Sep 12, 2023
2 parents 378eb63 + c389760 commit 029ae74
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 182 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: finnts
Title: Microsoft Finance Time Series Forecasting Framework
Version: 0.3.0.9001
Version: 0.3.0.9002
Authors@R:
c(person(given = "Mike",
family = "Tokic",
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# finnts 0.3.0.9001 (DEVELOPMENT VERSION)
# finnts 0.3.0.9002 (DEVELOPMENT VERSION)

## Improvements

- Tidymodels speed up
- Added external regressor support for ARIMA by introducing a new model option of `arimax`, which uses engineered features in addition to any external regressors supplied.
- Automated feature selection, refer to feature selection vignette for more details
- Error handling in hierarchical forecast reconciliation

## Bug Fixes

- Best model selection

# finnts 0.3.0

Expand Down
111 changes: 79 additions & 32 deletions R/final_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,58 +196,105 @@ final_models <- function(run_info,

single_model_tbl <- NULL
if (run_local_models) {
suppressWarnings(try(single_model_tbl <- read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-single_models.", run_info$data_output
),
return_type = "df"
),
silent = TRUE
))
single_model_tbl <- tryCatch(
{
read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-single_models.", run_info$data_output
),
return_type = "df"
)
},
warning = function(w) {
# do nothing
},
error = function(e) {
NULL
}
)
}

ensemble_model_tbl <- NULL
if (run_ensemble_models) {
suppressWarnings(try(ensemble_model_tbl <- read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-ensemble_models.", run_info$data_output
),
return_type = "df"
),
silent = TRUE
))
ensemble_model_tbl <- tryCatch(
{
read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-ensemble_models.", run_info$data_output
),
return_type = "df"
)
},
warning = function(w) {
# do nothing
},
error = function(e) {
NULL
}
)
}

global_model_tbl <- NULL
if (run_global_models) {
suppressWarnings(try(global_model_tbl <- read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-global_models.", run_info$data_output
),
return_type = "df"
),
silent = TRUE
))
global_model_tbl <- tryCatch(
{
read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-global_models.", run_info$data_output
),
return_type = "df"
)
},
warning = function(w) {
# do nothing
},
error = function(e) {
NULL
}
)
}

local_model_tbl <- single_model_tbl %>%
rbind(ensemble_model_tbl)

predictions_tbl <- local_model_tbl %>%
rbind(global_model_tbl) %>%
dplyr::select(Combo, Model_ID, Model_Name, Model_Type, Recipe_ID, Train_Test_ID, Date, Forecast, Target) %>%
dplyr::filter(Train_Test_ID %in% train_test_id_list)

# check if model averaging already happened
if ("Best_Model" %in% colnames(local_model_tbl %>% rbind(global_model_tbl))) {
# see if average models file exists and add to model tbl
average_model_tbl <- tryCatch(
{
read_file(run_info,
path = paste0(
"/forecasts/", hash_data(run_info$experiment_name), "-", hash_data(run_info$run_name),
"-", combo, "-average_models.", run_info$data_output
),
return_type = "df"
)
},
warning = function(w) {
# do nothing
},
error = function(e) {
NULL
}
)

local_model_tbl <- local_model_tbl %>%
rbind(average_model_tbl)

best_model_check <- TRUE
} else {
best_model_check <- FALSE
}

# combine all forecasts
predictions_tbl <- local_model_tbl %>%
rbind(global_model_tbl) %>%
dplyr::select(Combo, Model_ID, Model_Name, Model_Type, Recipe_ID, Train_Test_ID, Date, Forecast, Target) %>%
dplyr::filter(Train_Test_ID %in% train_test_id_list)

# get model list
if (!is.null(local_model_tbl)) {
local_model_list <- local_model_tbl %>%
Expand Down
Loading

0 comments on commit 029ae74

Please sign in to comment.