Skip to content

Commit

Permalink
Merge pull request #164 from microsoft/mitokic/07292024/multistep-bug
Browse files Browse the repository at this point in the history
Mitokic/07292024/multistep bug
  • Loading branch information
mitokic authored Aug 5, 2024
2 parents ab1c2a1 + 97aae40 commit e54ff28
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 19 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.4.0.9005
Version: 0.4.0.9006
Authors@R:
c(person(given = "Mike",
family = "Tokic",
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# finnts 0.4.0.9005 (DEVELOPMENT VERSION)
# finnts 0.4.0.9006 (DEVELOPMENT VERSION)

## Improvements

Expand All @@ -8,6 +8,7 @@
- Always save the most accurate model average, regardless if selected as best model. This allows for improved scaling with large data sets.
- Automatically condense large forecasts (+10k time series) into smaller amount of files to make it easier to read forecast outputs
- Improved weighted MAPE calculation across all time series
- Changed default for box_cox argument in `prep_data()` to FALSE

## Bug Fixes

Expand Down
5 changes: 4 additions & 1 deletion R/ensemble_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ ensemble_models <- function(run_info,
parallel_over = "everything"
)
) %>%
base::suppressMessages() %>%
base::suppressWarnings()

best_param <- tune::select_best(tune_results, metric = "rmse")
Expand Down Expand Up @@ -397,7 +398,9 @@ ensemble_models <- function(run_info,
pkgs = inner_packages,
parallel_over = "everything"
)
)
) %>%
base::suppressMessages() %>%
base::suppressWarnings()

final_fcst <- tune::collect_predictions(refit_tbl) %>%
dplyr::rename(
Expand Down
4 changes: 2 additions & 2 deletions R/multistep_cubist.R
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ cubist_multistep_predict_impl <- function(object, new_data, ...) {

xreg_tbl_final <- xreg_tbl %>%
dplyr::filter(
Run_Number >= start_val,
Run_Number <= lag_number
Run_Number >= as.numeric(start_val),
Run_Number <= as.numeric(lag_number)
)

if (!is.null(xreg_tbl)) {
Expand Down
4 changes: 2 additions & 2 deletions R/multistep_glmnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ glmnet_multistep_predict_impl <- function(object, new_data, ...) {

xreg_tbl_final <- xreg_tbl %>%
dplyr::filter(
Run_Number >= start_val,
Run_Number <= lag_number
Run_Number >= as.numeric(start_val),
Run_Number <= as.numeric(lag_number)
)

if (!is.null(xreg_tbl)) {
Expand Down
4 changes: 2 additions & 2 deletions R/multistep_mars.R
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ mars_multistep_predict_impl <- function(object, new_data, ...) {

xreg_tbl_final <- xreg_tbl %>%
dplyr::filter(
Run_Number >= start_val,
Run_Number <= lag_number
Run_Number >= as.numeric(start_val),
Run_Number <= as.numeric(lag_number)
)

if (!is.null(xreg_tbl)) {
Expand Down
4 changes: 2 additions & 2 deletions R/multistep_svm_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ svm_poly_multistep_predict_impl <- function(object, new_data, ...) {

xreg_tbl_final <- xreg_tbl %>%
dplyr::filter(
Run_Number >= start_val,
Run_Number <= lag_number
Run_Number >= as.numeric(start_val),
Run_Number <= as.numeric(lag_number)
)

if (!is.null(xreg_tbl)) {
Expand Down
4 changes: 2 additions & 2 deletions R/multistep_svm_rbf.R
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ svm_rbf_multistep_predict_impl <- function(object, new_data, ...) {

xreg_tbl_final <- xreg_tbl %>%
dplyr::filter(
Run_Number >= start_val,
Run_Number <= lag_number
Run_Number >= as.numeric(start_val),
Run_Number <= as.numeric(lag_number)
)

if (!is.null(xreg_tbl)) {
Expand Down
4 changes: 2 additions & 2 deletions R/multistep_xgboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ xgboost_multistep_predict_impl <- function(object, new_data, ...) {

xreg_tbl_temp <- xreg_tbl %>%
dplyr::filter(
Run_Number >= start_val,
Run_Number <= lag_number
Run_Number >= as.numeric(start_val),
Run_Number <= as.numeric(lag_number)
)

xreg_tbl_final <- xreg_tbl_temp %>%
Expand Down
2 changes: 1 addition & 1 deletion R/prep_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ prep_data <- function(run_info,
fiscal_year_start = 1,
clean_missing_values = TRUE,
clean_outliers = FALSE,
box_cox = TRUE,
box_cox = FALSE,
stationary = TRUE,
forecast_approach = "bottoms_up",
parallel_processing = NULL,
Expand Down
4 changes: 3 additions & 1 deletion R/prep_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,9 @@ model_hyperparameters <- function(run_info,

# update logging file
log_df <- log_df %>%
dplyr::mutate(num_hyperparameters = num_hyperparameters)
dplyr::mutate(
num_hyperparameters = num_hyperparameters
)

write_data(
x = log_df,
Expand Down
7 changes: 7 additions & 0 deletions R/read_write_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,17 @@ write_data <- function(x,
write_data_type <- function(x,
path,
type) {
if (type == "csv") {
if (nrow(x) == 1) {
type <- "log"
}
}

switch(type,
rds = saveRDS(x, path),
parquet = arrow::write_parquet(x, path),
csv = vroom::vroom_write(x, path, delim = ",", progress = FALSE),
log = utils::write.csv(x, path, row.names = FALSE),
qs = qs::qsave(x, path)
)
}
Expand Down
9 changes: 8 additions & 1 deletion R/train_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ train_models <- function(run_info,
parallel_over = "everything"
)
) %>%
tune::collect_predictions()
tune::collect_predictions() %>%
base::suppressMessages() %>%
base::suppressWarnings()

# finalize forecast
final_fcst <- refit_tbl %>%
Expand All @@ -534,6 +536,11 @@ train_models <- function(run_info,
dplyr::mutate(Hyperparameter_ID = hyperparameter_id) %>%
dplyr::select(-.row, -.config)

# check for future forecast
if (as.numeric(min(unique(final_fcst$Train_Test_ID))) != 1) {
stop("model is missing future forecast")
}

# undo differencing transformation
if (stationary & model %in% list_multivariate_models()) {
if (combo_hash == "All-Data") {
Expand Down
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.

0 comments on commit e54ff28

Please sign in to comment.