surrogate | R Documentation |
Fit a surrogate generalized linear model (GLM) to the segmented data.
surrogate(data, par_list)
data |
Data frame containing the segmented training data. |
par_list |
Named list, constructed via |
GLM (i.e., a "glm" object) which is fit to the segmented data
.
Extra info on arguments can be found at glm
.
## 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) %>%
segmentation(data = mtpl_be,
type = 'ngroups',
values = setNames(c(7, 8, 2, 2, 3), c('ageph', 'bm', 'coverage', 'fuel', 'bm_fuel'))) %>%
surrogate(par_list = alist(formula = nclaims ~ ageph_ + bm_ + coverage_ + fuel_ + bm_fuel_,
family = poisson(link = 'log'),
offset = log(expo)))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.