model_fit: Fit the insuRglm model

View source: R/model_fit.R

model_fitR Documentation

Fit the insuRglm model

Description

Fits the model with the current model formula. Computes and saves back many new attributes and objects. This is a required step before using model_visualize, model_compare, model_save, model_betas, model_crossval, model_lift, model_export and others. In case of a big dataset (especially many columns), declaring future::plan(multiprocess) beforehand might help to speed up the process.

Usage

model_fit(setup, glm_backend = c("setup", "speedglm", "stats"))

Arguments

setup

Setup object. Created at the start of the workflow. Usually piped in from previous step.

glm_backend

Character scalar. Either 'setup', 'speedglm' or 'stats'. Choosing 'setup', which is a default choice results in using the glm_backend set during setup. Choosing 'speedglm' or 'stats' will temporarily override this by using speedglm::speedglm or stats::glm.

Value

Setup object with updated attributes.

Examples

require(dplyr) # for the pipe operator
data('sev_train')

setup <- setup(
  data_train = sev_train,
  target = 'sev',
  weight = 'numclaims',
  family = 'gamma',
  keep_cols = c('pol_nbr', 'exposure', 'premium')
)

# parallel processing is supported and may be faster on bigger datasets
plan(multiprocess)

modeling <- setup %>%
  factor_add(pol_yr) %>%
  factor_add(agecat) %>%
  model_fit()

modeling %>%
  model_visualize(factors = 'fitted')

modeling %>%
  model_visualize(factors = 'unfitted')


realgabon/insuRglm documentation built on Jan. 2, 2023, 2:51 a.m.