Skip to content

Commit

Permalink
Merge pull request #85 from microsoft/users/mitokic/v0.2-smell-test
Browse files Browse the repository at this point in the history
v0.1.0 release by the awesome super @mike Tokic
  • Loading branch information
AKannanMSFT authored Nov 23, 2021
2 parents cba6266 + 6ef2f73 commit 57207bf
Show file tree
Hide file tree
Showing 23 changed files with 333 additions and 206 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
^docs$
^pkgdown$
^\.github$
CODE_OF_CONDUCT.md
SECURITY.md
SUPPORT.md
cran-comments.md
NEWS.md
3 changes: 1 addition & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
- {os: macOS-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}


# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
Expand Down
13 changes: 8 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: finnts
Title: Microsoft Finance Time Series Forecasting Framework
Version: 0.0.0.9000
Version: 0.1.0
Authors@R:
c(person(given = "Mike",
family = "Tokic",
role = c("aut", "cre"),
email = "mitokic@microsoft.com",
email = "mftokic@gmail.com",
comment = c(ORCID = "0000-0002-7630-7055")),
person(given = "Aadharsh",
family = "Kannan",
Expand Down Expand Up @@ -34,13 +34,17 @@ Imports:
doParallel,
dplyr,
earth,
foreach,
generics,
glmnet,
gtools,
hts,
kernlab,
lightgbm,
lubridate,
magrittr,
matrixcalc,
methods,
modeltime.ensemble,
modeltime.gluonts,
modeltime.resample,
Expand Down Expand Up @@ -68,11 +72,10 @@ Remotes:
Suggests:
rmarkdown,
knitr,
reactable,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Depends:
R (>= 3.6.0),
lubridate,
foreach,
R (>= 3.6.0),
modeltime
VignetteBuilder: knitr
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ export(tabnet)
export(tbats)
export(theta)
export(xgboost)
import(modeltime)
importFrom(foreach,"%do%")
importFrom(foreach,"%dopar%")
importFrom(lubridate,"%m+%")
importFrom(magrittr,"%>%")
importFrom(methods,formalArgs)
importFrom(stats,sd)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# finnts 0.1.0

* Initial CRAN Release
2 changes: 1 addition & 1 deletion R/azure_batch_parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ get_fcast_parallel_azure <- function(combo_list,

cli::cli_h2("Submitting Tasks to Azure Batch")

fcst <- foreach(i = combo_list, .combine = 'rbind',
fcst <- foreach::foreach(i = combo_list, .combine = 'rbind',
.packages = get_export_packages(),
.export = get_transfer_functions(),
.options.azure = list(maxTaskRetryCount = 0,
Expand Down
6 changes: 3 additions & 3 deletions R/configure_forecast_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ get_date_regex <- function(date_type){

#' Gets the back testing spacing
#'
#' Checks if back_test_spacing is set to auto and gets the right one
#' Checks if back_test_spacing is set to NULL and gets the right one
#'
#'
#' @param back_test_spacing back_test_spacing override
Expand All @@ -175,7 +175,7 @@ get_date_regex <- function(date_type){
get_back_test_spacing <- function(back_test_spacing,
date_type){

if(back_test_spacing != "auto") {
if(!is.null(back_test_spacing)) {
return(back_test_spacing)
}

Expand Down Expand Up @@ -218,7 +218,7 @@ get_back_test_scenario_hist_periods<- function(full_data_tbl,

hist_periods_80 <- floor(historical_periods*0.7) #used with time series CV in multivariate models

if(back_test_scenarios == "auto") {
if(is.null(back_test_scenarios)) {

historical_periods_20 <- floor(historical_periods*0.2)

Expand Down
56 changes: 37 additions & 19 deletions R/forecast_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,16 @@ construct_forecast_models <- function(full_data_tbl,
cli::cli_h2("Running Combo: {combo_value}")

# Copy functions into global environment within azure batch
if(parallel_processing == "azure_batch") {
global_env <- .GlobalEnv
export_env <- global_env$azbatchenv$exportenv

for(n in ls(export_env , all.names=TRUE)) {
assign(n, get(n, export_env), global_env)
if(!is.null(parallel_processing)) {
if(parallel_processing == "azure_batch") {

global_env <- .GlobalEnv
export_env <- global_env$azbatchenv$exportenv

for(n in ls(export_env , all.names=TRUE)) {
assign(n, get(n, export_env), global_env)
}

}
}

Expand All @@ -274,13 +278,22 @@ construct_forecast_models <- function(full_data_tbl,
run_data_full_tbl <- full_data_tbl %>%
combo_specific_filter(combo_value,
combo_variables)

cli::cli_h3("Initial Feature Engineering")

# Run all recipes
if(is.null(recipes_to_run)) {
run_all_recipes_override <- FALSE
} else if(recipes_to_run == "all") {
run_all_recipes_override <- TRUE
} else {
run_all_recipes_override <- FALSE
}

# recipe 1: standard feature engineering
run_data_full_recipe_1 <- NULL

if(is.null(recipes_to_run) | "R1" %in% recipes_to_run | sum(recipes_to_run == "all") == 1) {
if(is.null(recipes_to_run) | "R1" %in% recipes_to_run | run_all_recipes_override) {

run_data_full_recipe_1 <- run_data_full_tbl %>%
multivariate_prep_recipe_1(external_regressors = external_regressors,
Expand All @@ -301,7 +314,7 @@ construct_forecast_models <- function(full_data_tbl,
# recipe 2: custom horizon specific feature engineering
run_data_full_recipe_2 <- NULL

if((is.null(recipes_to_run) & date_type %in% c("month", "quarter", "year")) | "R2" %in% recipes_to_run | sum(recipes_to_run == "all") == 1) {
if((is.null(recipes_to_run) & date_type %in% c("month", "quarter", "year")) | "R2" %in% recipes_to_run | run_all_recipes_override) {

run_data_full_recipe_2 <- run_data_full_tbl %>%
multivariate_prep_recipe_2(external_regressors = external_regressors,
Expand Down Expand Up @@ -332,7 +345,7 @@ construct_forecast_models <- function(full_data_tbl,
combined_models_recipe_2 <- modeltime::modeltime_table()

# parallel processing
if(run_model_parallel==TRUE & parallel_processing!="local_machine") {
if(run_model_parallel == TRUE) {
parallel_args <- init_parallel_within(parallel_processing, num_cores)
}

Expand All @@ -353,12 +366,17 @@ construct_forecast_models <- function(full_data_tbl,
models_to_go_over <- names(model_list)

# PCA
if(sum(pca == TRUE) == 1 | (combo_value == "All-Data" & is.null(pca)) | (is.null(pca) & date_type %in% c("day", "week"))) {
if((combo_value == "All-Data" & is.null(pca)) | (is.null(pca) & date_type %in% c("day", "week"))) {
run_pca <- TRUE
} else if(is.null(pca)) {
run_pca <- FALSE
} else if(pca == TRUE) {
run_pca <- TRUE
} else {
run_pca <- FALSE
}


# train each model
for(model_name in models_to_go_over){

model_fn <- as.character(model_list[model_name])
Expand Down Expand Up @@ -390,15 +408,15 @@ construct_forecast_models <- function(full_data_tbl,
try(combined_models_recipe_1 <- modeltime::add_modeltime_model(combined_models_recipe_1,
mdl_called,
location = "top") %>%
update_model_description(1, model_name),
modeltime::update_model_description(1, model_name),
silent = TRUE)

}else{


freq_val <- frequency

if(((model_name %in% r1_models) | (model_name %in% r2_models)) & (is.null(recipes_to_run) | sum(recipes_to_run == "all") == 1 | "R1" %in% recipes_to_run)){
if(((model_name %in% r1_models) | (model_name %in% r2_models)) & (is.null(recipes_to_run) | run_all_recipes_override | "R1" %in% recipes_to_run)){

add_name <- paste0(model_name,"-R1",model_name_suffix)
if(model_name %in% deep_nn_models){
Expand All @@ -422,12 +440,12 @@ construct_forecast_models <- function(full_data_tbl,
try(combined_models_recipe_1 <- modeltime::add_modeltime_model(combined_models_recipe_1,
mdl_called,
location = "top") %>%
update_model_description(1, add_name),
modeltime::update_model_description(1, add_name),
silent = TRUE)

}

if(model_name %in% r2_models & ("R2" %in% recipes_to_run | sum(recipes_to_run == "all") == 1 | (is.null(recipes_to_run) & date_type %in% c("month", "quarter", "year")))){
if(model_name %in% r2_models & ("R2" %in% recipes_to_run | run_all_recipes_override | (is.null(recipes_to_run) & date_type %in% c("month", "quarter", "year")))){

add_name <- paste0(model_name,"-R2",model_name_suffix)
try(mdl_called <- invoke_forecast_function(fn_to_invoke = model_fn,
Expand All @@ -446,7 +464,7 @@ construct_forecast_models <- function(full_data_tbl,
try(combined_models_recipe_2 <- modeltime::add_modeltime_model(combined_models_recipe_2,
mdl_called,
location = "top") %>%
update_model_description(1, add_name),
modeltime::update_model_description(1, add_name),
silent = TRUE)
}

Expand Down Expand Up @@ -651,7 +669,7 @@ construct_forecast_models <- function(full_data_tbl,
try(combined_ensemble_models <- modeltime::add_modeltime_model(combined_ensemble_models,
mdl_ensemble,
location = "top") %>%
update_model_description(1, add_name),
modeltime::update_model_description(1, add_name),
silent = TRUE)
}

Expand Down Expand Up @@ -746,7 +764,7 @@ construct_forecast_models <- function(full_data_tbl,
}

#stop parallel processing
if(run_model_parallel==TRUE & parallel_processing!="local_machine"){
if(run_model_parallel==TRUE){
exit_parallel_within(parallel_args)
}

Expand Down
Loading

0 comments on commit 57207bf

Please sign in to comment.