Obtain insights from a black box model in the form of feature effects.
insights( mfit, vars, data, interactions = "user", hcut = 0.75, pred_fun = NULL, fx_in = NULL, ncores = -1 )
mfit | Fitted model object (e.g., a "gbm" or "randomForest" object). |
---|---|
vars | Character vector specifying the features to get insights on. |
data | Data frame containing the original training data. |
interactions | String specifying how to deal with interaction effects:
|
hcut | Numeric in the range [0,1] specifying the cut-off value for the
normalized cumulative H-statistic over all two-way interactions, ordered
from most to least important, between the features in |
pred_fun | Optional prediction function to calculate feature effects for
the model in |
fx_in | Optional named list of data frames containing feature effects
for features in |
ncores | Integer specifying the number of cores to use. The default
|
List of tidy data frames (i.e., "tibble" objects), containing the
partial dependencies for the features (and interactions) in vars
.
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'), data = mtpl_be, interactions = 'auto', hcut = 0.75, pred_fun = gbm_fun) gbm_fit %>% insights(vars = c('ageph', 'bm', 'coverage', 'fuel', 'bm_fuel'), data = mtpl_be, interactions = 'user', pred_fun = gbm_fun) }