Skip to content

Commit 57207bf

Browse files
authored
Merge pull request #85 from microsoft/users/mitokic/v0.2-smell-test
v0.1.0 release by the awesome super @mike Tokic
2 parents cba6266 + 6ef2f73 commit 57207bf

23 files changed

+333
-206
lines changed

.Rbuildignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
^docs$
66
^pkgdown$
77
^\.github$
8+
CODE_OF_CONDUCT.md
9+
SECURITY.md
10+
SUPPORT.md
11+
cran-comments.md
12+
NEWS.md

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ jobs:
2525
- {os: macOS-latest, r: 'release'}
2626

2727
- {os: windows-latest, r: 'release'}
28-
# Use 3.6 to trigger usage of RTools35
29-
- {os: windows-latest, r: '3.6'}
28+
3029

3130
# Use older ubuntu to maximise backward compatibility
3231
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}

DESCRIPTION

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Package: finnts
22
Title: Microsoft Finance Time Series Forecasting Framework
3-
Version: 0.0.0.9000
3+
Version: 0.1.0
44
Authors@R:
55
c(person(given = "Mike",
66
family = "Tokic",
77
role = c("aut", "cre"),
8-
email = "mitokic@microsoft.com",
8+
email = "mftokic@gmail.com",
99
comment = c(ORCID = "0000-0002-7630-7055")),
1010
person(given = "Aadharsh",
1111
family = "Kannan",
@@ -34,13 +34,17 @@ Imports:
3434
doParallel,
3535
dplyr,
3636
earth,
37+
foreach,
3738
generics,
3839
glmnet,
3940
gtools,
4041
hts,
4142
kernlab,
4243
lightgbm,
44+
lubridate,
45+
magrittr,
4346
matrixcalc,
47+
methods,
4448
modeltime.ensemble,
4549
modeltime.gluonts,
4650
modeltime.resample,
@@ -68,11 +72,10 @@ Remotes:
6872
Suggests:
6973
rmarkdown,
7074
knitr,
75+
reactable,
7176
testthat (>= 3.0.0)
7277
Config/testthat/edition: 3
7378
Depends:
74-
R (>= 3.6.0),
75-
lubridate,
76-
foreach,
79+
R (>= 3.6.0),
7780
modeltime
7881
VignetteBuilder: knitr

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ export(tabnet)
2525
export(tbats)
2626
export(theta)
2727
export(xgboost)
28+
import(modeltime)
29+
importFrom(foreach,"%do%")
30+
importFrom(foreach,"%dopar%")
31+
importFrom(lubridate,"%m+%")
32+
importFrom(magrittr,"%>%")
33+
importFrom(methods,formalArgs)
34+
importFrom(stats,sd)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# finnts 0.1.0
3+
4+
* Initial CRAN Release

R/azure_batch_parallel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ get_fcast_parallel_azure <- function(combo_list,
2222

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

25-
fcst <- foreach(i = combo_list, .combine = 'rbind',
25+
fcst <- foreach::foreach(i = combo_list, .combine = 'rbind',
2626
.packages = get_export_packages(),
2727
.export = get_transfer_functions(),
2828
.options.azure = list(maxTaskRetryCount = 0,

R/configure_forecast_run.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ get_date_regex <- function(date_type){
164164

165165
#' Gets the back testing spacing
166166
#'
167-
#' Checks if back_test_spacing is set to auto and gets the right one
167+
#' Checks if back_test_spacing is set to NULL and gets the right one
168168
#'
169169
#'
170170
#' @param back_test_spacing back_test_spacing override
@@ -175,7 +175,7 @@ get_date_regex <- function(date_type){
175175
get_back_test_spacing <- function(back_test_spacing,
176176
date_type){
177177

178-
if(back_test_spacing != "auto") {
178+
if(!is.null(back_test_spacing)) {
179179
return(back_test_spacing)
180180
}
181181

@@ -218,7 +218,7 @@ get_back_test_scenario_hist_periods<- function(full_data_tbl,
218218

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

221-
if(back_test_scenarios == "auto") {
221+
if(is.null(back_test_scenarios)) {
222222

223223
historical_periods_20 <- floor(historical_periods*0.2)
224224

R/forecast_models.R

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,16 @@ construct_forecast_models <- function(full_data_tbl,
259259
cli::cli_h2("Running Combo: {combo_value}")
260260

261261
# Copy functions into global environment within azure batch
262-
if(parallel_processing == "azure_batch") {
263-
global_env <- .GlobalEnv
264-
export_env <- global_env$azbatchenv$exportenv
265-
266-
for(n in ls(export_env , all.names=TRUE)) {
267-
assign(n, get(n, export_env), global_env)
262+
if(!is.null(parallel_processing)) {
263+
if(parallel_processing == "azure_batch") {
264+
265+
global_env <- .GlobalEnv
266+
export_env <- global_env$azbatchenv$exportenv
267+
268+
for(n in ls(export_env , all.names=TRUE)) {
269+
assign(n, get(n, export_env), global_env)
270+
}
271+
268272
}
269273
}
270274

@@ -274,13 +278,22 @@ construct_forecast_models <- function(full_data_tbl,
274278
run_data_full_tbl <- full_data_tbl %>%
275279
combo_specific_filter(combo_value,
276280
combo_variables)
277-
281+
278282
cli::cli_h3("Initial Feature Engineering")
279283

284+
# Run all recipes
285+
if(is.null(recipes_to_run)) {
286+
run_all_recipes_override <- FALSE
287+
} else if(recipes_to_run == "all") {
288+
run_all_recipes_override <- TRUE
289+
} else {
290+
run_all_recipes_override <- FALSE
291+
}
292+
280293
# recipe 1: standard feature engineering
281294
run_data_full_recipe_1 <- NULL
282295

283-
if(is.null(recipes_to_run) | "R1" %in% recipes_to_run | sum(recipes_to_run == "all") == 1) {
296+
if(is.null(recipes_to_run) | "R1" %in% recipes_to_run | run_all_recipes_override) {
284297

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

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

306319
run_data_full_recipe_2 <- run_data_full_tbl %>%
307320
multivariate_prep_recipe_2(external_regressors = external_regressors,
@@ -332,7 +345,7 @@ construct_forecast_models <- function(full_data_tbl,
332345
combined_models_recipe_2 <- modeltime::modeltime_table()
333346

334347
# parallel processing
335-
if(run_model_parallel==TRUE & parallel_processing!="local_machine") {
348+
if(run_model_parallel == TRUE) {
336349
parallel_args <- init_parallel_within(parallel_processing, num_cores)
337350
}
338351

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

355368
# PCA
356-
if(sum(pca == TRUE) == 1 | (combo_value == "All-Data" & is.null(pca)) | (is.null(pca) & date_type %in% c("day", "week"))) {
369+
if((combo_value == "All-Data" & is.null(pca)) | (is.null(pca) & date_type %in% c("day", "week"))) {
370+
run_pca <- TRUE
371+
} else if(is.null(pca)) {
372+
run_pca <- FALSE
373+
} else if(pca == TRUE) {
357374
run_pca <- TRUE
358375
} else {
359376
run_pca <- FALSE
360377
}
361-
378+
379+
# train each model
362380
for(model_name in models_to_go_over){
363381

364382
model_fn <- as.character(model_list[model_name])
@@ -390,15 +408,15 @@ construct_forecast_models <- function(full_data_tbl,
390408
try(combined_models_recipe_1 <- modeltime::add_modeltime_model(combined_models_recipe_1,
391409
mdl_called,
392410
location = "top") %>%
393-
update_model_description(1, model_name),
411+
modeltime::update_model_description(1, model_name),
394412
silent = TRUE)
395413

396414
}else{
397415

398416

399417
freq_val <- frequency
400418

401-
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)){
419+
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)){
402420

403421
add_name <- paste0(model_name,"-R1",model_name_suffix)
404422
if(model_name %in% deep_nn_models){
@@ -422,12 +440,12 @@ construct_forecast_models <- function(full_data_tbl,
422440
try(combined_models_recipe_1 <- modeltime::add_modeltime_model(combined_models_recipe_1,
423441
mdl_called,
424442
location = "top") %>%
425-
update_model_description(1, add_name),
443+
modeltime::update_model_description(1, add_name),
426444
silent = TRUE)
427445

428446
}
429447

430-
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")))){
448+
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")))){
431449

432450
add_name <- paste0(model_name,"-R2",model_name_suffix)
433451
try(mdl_called <- invoke_forecast_function(fn_to_invoke = model_fn,
@@ -446,7 +464,7 @@ construct_forecast_models <- function(full_data_tbl,
446464
try(combined_models_recipe_2 <- modeltime::add_modeltime_model(combined_models_recipe_2,
447465
mdl_called,
448466
location = "top") %>%
449-
update_model_description(1, add_name),
467+
modeltime::update_model_description(1, add_name),
450468
silent = TRUE)
451469
}
452470

@@ -651,7 +669,7 @@ construct_forecast_models <- function(full_data_tbl,
651669
try(combined_ensemble_models <- modeltime::add_modeltime_model(combined_ensemble_models,
652670
mdl_ensemble,
653671
location = "top") %>%
654-
update_model_description(1, add_name),
672+
modeltime::update_model_description(1, add_name),
655673
silent = TRUE)
656674
}
657675

@@ -746,7 +764,7 @@ construct_forecast_models <- function(full_data_tbl,
746764
}
747765

748766
#stop parallel processing
749-
if(run_model_parallel==TRUE & parallel_processing!="local_machine"){
767+
if(run_model_parallel==TRUE){
750768
exit_parallel_within(parallel_args)
751769
}
752770

0 commit comments

Comments
 (0)