Create a grid of lambda values that result in a unique grouping.
lambda_grid( fx_vars, max_ngrps = 15, lambda_range = as.vector(outer(seq(1, 10, 0.1), 10^(-7:3))) )
fx_vars | List of data frames containing the feature effects. |
---|---|
max_ngrps | Integer specifying the maximum number of groups that each feature's values/levels are allowed to be grouped into. |
lambda_range | Numeric vector of possible values for lambda. |
Tidy data frame (i.e., a "tibble" object) with the lambda grid. The
first column contains the lambda values from lambda_range
which
result in a unique grouping for the features in fx_vars
. There is
one column for each feature containing the optimal number of groups
corresponding to those lambda values.
if (FALSE) { data('mtpl_be') features <- setdiff(names(mtpl_be), c('id', 'nclaims', 'expo', 'long', 'lat')) set.seed(12345) gbm_fit <- gbm::gbm(as.formula(paste('nclaims ~', paste(features, collapse = ' + '))), distribution = 'poisson', data = mtpl_be, n.trees = 50, interaction.depth = 3, shrinkage = 0.1) gbm_fun <- function(object, newdata) mean(predict(object, newdata, n.trees = object$n.trees, type = 'response')) gbm_fit %>% insights(vars = c('ageph', 'bm', 'coverage', 'fuel', 'bm_fuel'), data = mtpl_be, interactions = 'user', pred_fun = gbm_fun) %>% lambda_grid }