View source: R/custom_factor.R
custom_factor | R Documentation |
Simplifies simple factor to custom factor, which usually means that some of the original levels are merged together.
Must be used within factor_modify
function. This is usually done with categorical variables where order of levels doesn't matter.
custom_factor(x, mapping)
x |
Unquoted symbol. Predictor to be simplified. Must be present in the modeling dataset. |
mapping |
Integer vector. Mapping to use for simplification. Length must be equal to length of unique levels of the predictor. |
Original vector with updated attributes.
factor_modify
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') ) modeling <- setup %>% factor_add(pol_yr) %>% factor_add(area) %>% model_fit() %>% model_save('model1') %>% factor_modify(area = custom_factor(area, mapping = c(1, 2, 3, 1, 4, 4))) %>% model_fit()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.