Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zanotti committed Jan 16, 2024
1 parent b8f9220 commit 3259576
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions dashboard/R/fit_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,9 @@ update_tune_model_parameters <- function(method, params) {
}
}

# rimappare il parametro tune_elanet

mth_params <- getOption("tsf.dashboard.methods_params")[["Elastic Net"]]
tune_params <- clean_chr_inv(params$tune_elanet)
mth_params <- getOption("tsf.dashboard.methods_params")[[method]]
prm_name <- grep("_xx_", names(params), value = TRUE)
tune_params <- clean_chr_inv(params[[prm_name]])
is_to_tune <- mth_params %in% tune_params
params_list <- map2(mth_params, is_to_tune, get_tune) |> set_names(mth_params)
update_params <- c(params, params_list)
Expand Down Expand Up @@ -521,7 +520,7 @@ fit_model_tuning <- function(
# grid_spec <- generate_grid_spec(method, model_spec, grid_size, seed)

# tuning
if (n_folds > 10 | grid_size > 25) {
if (n_folds > 20 | grid_size > 25) {
doFuture::registerDoFuture()
future::plan(strategy = "multisession", workers = parallelly::availableCores() - 1)
message("Number of parallel workers: ", future::nbrOfWorkers())
Expand All @@ -531,7 +530,7 @@ fit_model_tuning <- function(
resamples = cv_splits,
grid = params$grid_size, # grid_spec
metrics = modeltime::default_forecast_accuracy_metric_set(),
control = tune::control_grid(save_pred = FALSE)
control = tune::control_grid(save_pred = FALSE, allow_par = TRUE)
)
future::plan(strategy = "sequential")

Expand Down
10 changes: 4 additions & 6 deletions dashboard/R/generate_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ generate_forecast <- function(
ensemble_method = NULL
) {

splits <- timetk::time_series_split(
data, date_var = date,
initial = nrow(data) - n_assess,
assess = n_assess,
cumulative = ifelse(assess_type == "Expanding", TRUE, FALSE)
)
# initial split
splits <- generate_initial_split(data, n_assess, assess_type)
train_tbl <- training(splits) |> select(-id, -frequency)
test_tbl <- testing(splits) |> select(-id, -frequency)

# future split
future_tbl <- future_frame(data, .date_var = date, .length_out = n_future)

# model summary
Expand Down
2 changes: 1 addition & 1 deletion dashboard/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ input <- list(
n_folds = 5,
metric = "RMSE",
grid_size = 10,
tune_rf = c("rf_mtry")
tune_xx_rf = c("rf_mtry")
)

data = data_selected
Expand Down
4 changes: 3 additions & 1 deletion dashboard/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Next steps:
- documentazione in alto a destra

To Do:
- rimappare tune_elanet ecc
- aggiungere rbf_sigma conditional su svm_rbf
- finire update_tune_model_parameters con mapping parametri (occhio, non mtry ma rf_mtry)
- testare flusso optimize fino al forecast
- change split in generate_forecast
- fare la funzione parse_parameters per ottenere i nomi da mostrare in UI dal parametro

- aggiungere metodi di automl (h2o)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/tsf_dashboard.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ conditionalPanel(
condition = "input.tune_method == 'Elastic Net'",
h5("Algorithm hyperparameters to optimize: "),
pickerInput(
inputId = "tune_elanet", label = NULL,
inputId = "tune_xx_elanet", label = NULL, # _xx_ need to recognize it easily in update_tune_model_parameters()
choices = methods_params_cl[["Elastic Net"]], multiple = TRUE,
selected = methods_params_cl[["Elastic Net"]][2],
options = list("actions-box" = TRUE)
Expand Down

0 comments on commit 3259576

Please sign in to comment.