lambda_grid: Lambda grid

View source: R/lambda_grid.R

lambda_gridR Documentation

Lambda grid

Description

Create a grid of lambda values that result in a unique grouping.

Usage

lambda_grid(
  fx_vars,
  max_ngrps = 15,
  lambda_range = as.vector(outer(seq(1, 10, 0.1), 10^(-7:3)))
)

Arguments

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.

Value

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.

Examples

## Not run: 
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

## End(Not run)

henckr/maidrr documentation built on July 27, 2023, 3:17 p.m.