Base learner: tune hyperparameters and retrieve the best model
Source:R/base_learner.R
fit_base_learner.Rd
Multilayer perceptron model with different configurations of hidden units, dropout, activation, and learning rate using brulee and tidymodels. With proper settings, users can utilize graphics processing units (GPU) to speed up the training process.
Usage
fit_base_learner(
learner = c("mlp", "xgb", "lgb", "elnet"),
dt_full,
r_subsample = 0.3,
model = NULL,
folds = 5L,
cv_mode = c("spatiotemporal", "spatial", "temporal"),
args_generate_cv = NULL,
tune_mode = "grid",
tune_bayes_iter = 10L,
tune_grid_in = NULL,
tune_grid_size = 10L,
learn_rate = 0.1,
yvar = "Arithmetic.Mean",
xvar = seq(5, ncol(dt_sample)),
nthreads = 8L,
trim_resamples = FALSE,
return_best = TRUE,
...
)
Arguments
- learner
character(1). The base learner to be used. Default is "mlp". Available options are "mlp", "xgb", "lgb", "elnet".
- dt_full
The full data table to be used for prediction.
- r_subsample
numeric(1). The proportion of rows to be used.
- model
The parsnip model object. Preferably generated from
switch_model
.- folds
integer(1). Number of cross-validation folds. If NULL,
cv_mode
should be defined to be used in rsample::vfold_cv.- cv_mode
character(1). Cross-validation mode. Default is "spatiotemporal". Available options are "spatiotemporal", "spatial", "temporal".
- args_generate_cv
List of arguments to be passed to
switch_generate_cv_rset
function.- tune_mode
character(1). Hyperparameter tuning mode. Default is "grid", "bayes" is acceptable.
- tune_bayes_iter
integer(1). The number of iterations for Bayesian optimization. Default is 10. Only used when
tune_mode = "bayes"
.- tune_grid_in
data.frame object that includes the grid for hyperparameter tuning.
tune_grid_size
rows will be randomly picked from this data.frame for grid search.- tune_grid_size
integer(1). The number of grid size for hyperparameter tuning. Default is 10. Only used when
tune_mode = "grid"
.- learn_rate
The learning rate for the model. For branching purpose. Default is 0.1.
- yvar
The target variable.
- xvar
The predictor variables.
- nthreads
integer(1). The number of threads to be used for tuning. Default is 8L.
learner = "elnet"
will utilize the multiple threads infuture::multicore()
plan.- trim_resamples
logical(1). Default is TRUE, which replaces the actual data.frames in splits column of
tune_results
object with NA.- return_best
logical(1). If TRUE, the best tuned model is returned.
- ...
Additional arguments to be passed.
Details
LightGBM model is fitted at the defined rate (r_subsample
) of
the input dataset by grid or Bayesian optimization search.
With proper settings, users can utilize graphics
processing units (GPU) to speed up the training process.
XGBoost model is fitted at the defined rate (r_subsample
) of
the input dataset by grid or Bayesian optimization search.
With proper settings, users can utilize graphics
processing units (GPU) to speed up the training process.
Elastic net model is fitted at the defined rate (r_subsample
) of
the input dataset by grid search or Bayesian optimization.
MLP: Hyperparameters
hidden_units
,dropout
,activation
, andlearn_rate
are tuned.With tune_mode = "grid"
, users can modifylearn_rate
explicitly, and other hyperparameters will be predefined (56 combinations perlearn_rate
for mlp).XGBoost: Hyperparameters
mtry
,ntrees
, andlearn_rate
are tuned. Withtune_mode = "grid"
, users can modifylearn_rate
explicitly, and other hyperparameters will be predefined (30 combinations perlearn_rate
).LightGBM: Hyperparameters
mtry
,ntrees
, andlearn_rate
are tuned. Withtune_mode = "grid"
, users can modifylearn_rate
explicitly, and other hyperparameters will be predefined (30 combinations perlearn_rate
).Elastic net: Hyperparameters
mixture
andpenalty
are tuned.
Tuning is performed based on random grid search (size = 10).