Skip to content

Commit

Permalink
new box-cox and differencing updates, new list_models() function
Browse files Browse the repository at this point in the history
  • Loading branch information
mitokic committed Aug 29, 2023
1 parent c389760 commit 0e61683
Show file tree
Hide file tree
Showing 12 changed files with 540 additions and 41 deletions.
3 changes: 2 additions & 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.9002
Version: 0.3.0.9003
Authors@R:
c(person(given = "Mike",
family = "Tokic",
Expand Down Expand Up @@ -33,6 +33,7 @@ Imports:
doParallel,
dplyr,
earth,
feasts,
foreach,
fs,
generics,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(get_prepped_data)
export(get_prepped_models)
export(get_run_info)
export(get_trained_models)
export(list_models)
export(prep_data)
export(prep_models)
export(set_run_info)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Tidymodels speed up
- Automated feature selection, refer to feature selection vignette for more details
- Error handling in hierarchical forecast reconciliation
- Box-cox and differencing transformations
- Added new function, `list_models()`, that lists available models in the package

## Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions R/ensemble_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ ensemble_models <- function(run_info,
}

# get ensemble models to run
ensemble_model_list <- c("cubist", "glmnet", "svm-poly", "svm-rbf", "xgboost")
ensemble_model_list <- list_ensemble_models()

if (is.na(models_to_run) & is.na(models_not_to_run)) {
# do nothing, using existing ml_models list
} else if (is.na(models_to_run) & !is.na(models_not_to_run)) {
ensemble_model_list <- setdiff(ensemble_model_list, stringr::str_split(models_not_to_run, "---")[[1]])
} else {
ensemble_model_list <- ensemble_model_list[c("cubist", "glmnet", "svm-poly", "svm-rbf", "xgboost") %in% stringr::str_split(models_to_run, "---")[[1]]]
ensemble_model_list <- ensemble_model_list[list_ensemble_models() %in% stringr::str_split(models_to_run, "---")[[1]]]
}

# parallel run info
Expand Down
34 changes: 24 additions & 10 deletions R/feature_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,30 @@ select_features <- function(input_data,
dplyr::select(Feature, Vote, Auto_Accept)

# cubist feature importance
vip_cubist_results <- vip_cubist_fn(
input_data,
seed
) %>%
dplyr::rename(Feature = Variable) %>%
dplyr::mutate(
Vote = 1,
Auto_Accept = 0
) %>%
dplyr::select(Feature, Vote, Auto_Accept)
vip_cubist_results <- tryCatch(
{
vip_cubist_fn(
input_data,
seed
) %>%
dplyr::rename(Feature = Variable) %>%
dplyr::mutate(
Vote = 1,
Auto_Accept = 0
) %>%
dplyr::select(Feature, Vote, Auto_Accept)
},
warning = function(w) {
# do nothing
},
error = function(e) {
tibble::tibble()
}
)

if (nrow(vip_cubist_results) == 0) {
votes_needed <- votes_needed-1
}

# lasso regression feature importance
vip_lm_initial <- vip_lm_fn(
Expand Down
78 changes: 78 additions & 0 deletions R/models.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
#' List all available models
#'
#' @return list of models
#' @export
list_models <- function() {
list <- c(
"arima", "arima-boost", "cubist", "croston", "ets", "glmnet", "mars", "meanf",
"nnetar", "nnetar-xregs", "prophet", "prophet-boost", "prophet-xregs", "snaive",
"stlm-arima", "stlm-ets", "svm-poly", "svm-rbf", "tbats", "theta", "xgboost"
)

return(list)
}

#' List models with hyperparameters
#'
#'
#' @return list of models
#' @noRd
list_hyperparmater_models <- function() {
list <- c(
"arima-boost", "cubist", "glmnet", "mars",
"nnetar", "nnetar-xregs", "prophet", "prophet-boost",
"prophet-xregs", "svm-poly", "svm-rbf", "xgboost"
)

return(list)
}

#' List ensemble models
#'
#'
#' @return list of models
#' @noRd
list_ensemble_models <- function() {
list <- c(
"cubist", "glmnet", "svm-poly", "svm-rbf", "xgboost"
)

return(list)
}

#' List models capable with R2 recipe
#'
#'
#' @return list of models
#' @noRd
list_r2_models <- function() {
list <- c("cubist", "glmnet", "svm-poly", "svm-rbf", "xgboost")

return(list)
}

#' List global models
#'
#'
#' @return list of models
#' @noRd
list_global_models <- function() {
list <- c("cubist", "glmnet", "mars", "svm-poly", "svm-rbf", "xgboost")

return(list)
}

#' List multivariate models
#'
#'
#' @return list of models
#' @noRd
list_multivariate_models <- function() {
list <- c(
list_global_models(), "arima-boost", "prophet-boost", "prophet-xregs",
"nnetar-xregs"
)

return(list)
}

#' Gets a simple recipe
#'
#' @param train_data Training Data
Expand Down
Loading

0 comments on commit 0e61683

Please sign in to comment.