Segmentation of observations based on the grouping of feature effects.
segmentation(fx_vars, data, type, values, max_ngrps = 15)
fx_vars | List of data frames containing the feature effects. |
---|---|
data | Data frame containing the original training data. |
type | String specifying the type of segmentation. Options are:
|
values | The values for |
max_ngrps | Integer specifying the maximum number of groups that each
feature's values/levels are allowed to be grouped into. Only used when
determinining the optimal number of groups via |
Data frame with the segmented data. The grouped features are added to
the original data
and have a trailing underscore in their name.
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) %>% segmentation(data = mtpl_be, type = 'ngroups', values = setNames(c(7, 8, 2, 2, 3), c('ageph', 'bm', 'coverage', 'fuel', 'bm_fuel'))) }