Skip to content

Commit

Permalink
fix box-cox transformation for time series that only have 1-2 non-zer…
Browse files Browse the repository at this point in the history
…o target values
  • Loading branch information
mitokic committed Sep 27, 2023
1 parent 121686b commit 7e34087
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 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.9004
Version: 0.3.0.9005
Authors@R:
c(person(given = "Mike",
family = "Tokic",
Expand Down
2 changes: 1 addition & 1 deletion R/prep_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ apply_box_cox <- function(df) {

diff_info <- tibble::tibble(
Combo = unique(df$Combo),
Box_Cox_Lambda = NULL
Box_Cox_Lambda = NA
)

for (column_name in names(df)) {
Expand Down
27 changes: 17 additions & 10 deletions R/train_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -564,22 +564,29 @@ train_models <- function(run_info,
dplyr::select(Box_Cox_Lambda) %>%
dplyr::pull(Box_Cox_Lambda)

final_fcst_return <- x %>%
dplyr::mutate(
Forecast = timetk::box_cox_inv_vec(Forecast, lambda = lambda),
Target = timetk::box_cox_inv_vec(Target, lambda = lambda)
)
if (!is.na(lambda)) {
final_fcst_return <- x %>%
dplyr::mutate(
Forecast = timetk::box_cox_inv_vec(Forecast, lambda = lambda),
Target = timetk::box_cox_inv_vec(Target, lambda = lambda)
)
} else {
final_fcst_return <- x
}

return(final_fcst_return)
}) %>%
dplyr::bind_rows()
} else {
lambda <- filtered_combo_info_tbl$Box_Cox_Lambda
final_fcst <- final_fcst %>%
dplyr::mutate(
Forecast = timetk::box_cox_inv_vec(Forecast, lambda = lambda),
Target = timetk::box_cox_inv_vec(Target, lambda = lambda)
)

if (!is.na(lambda)) {
final_fcst <- final_fcst %>%
dplyr::mutate(
Forecast = timetk::box_cox_inv_vec(Forecast, lambda = lambda),
Target = timetk::box_cox_inv_vec(Target, lambda = lambda)
)
}
}
}

Expand Down

0 comments on commit 7e34087

Please sign in to comment.