ModelBoot | R Documentation |
A ModelBoot
S7 object contains full-model bootstrapped statistics and ALE data for a trained model. Full-model bootstrapping (as distinct from data-only bootstrapping) retrains a model for each bootstrap iteration. Thus, it can be rather slow, though it is much more reliable. However, for obtaining bootstrapped ALE data, plots, and statistics, full-model bootstrapping as provided by ModelBoot
is only necessary for models that have not been developed by cross-validation. For cross-validated models, it is sufficient (and much faster) to create a regular [ALE()]
object with bootstrapping by setting the boot_it
argument in its constructor. In fact, full-model bootstrapping with ModelBoot
is often infeasible for slow machine-learning models trained on large datasets, which should rather be cross-validated to assure their reliability. However, for models that have not been cross-validated, full-model bootstrapping with ModelBoot
is necessary for reliable results. Further details follow below; see also vignette('ale-statistics')
.
ModelBoot(
model,
data = NULL,
...,
model_call_string = NULL,
model_call_string_vars = character(),
parallel = "all",
model_packages = NULL,
y_col = NULL,
positive = TRUE,
pred_fun = function(object, newdata, type = pred_type) {
stats::predict(object =
object, newdata = newdata, type = type)
},
pred_type = "response",
boot_it = 100,
boot_alpha = 0.05,
boot_centre = "mean",
seed = 0,
output_model_stats = TRUE,
output_model_coefs = TRUE,
output_ale = TRUE,
output_boot_data = FALSE,
ale_options = list(),
ale_p = "auto",
tidy_options = list(),
glance_options = list(),
silent = FALSE
)
model |
Required. See documentation for |
data |
dataframe. Dataset to be bootstrapped. This must be the same data on which the |
... |
not used. Inserted to require explicit naming of subsequent arguments. |
model_call_string |
character(1). If |
model_call_string_vars |
character. Names of variables included in |
parallel , model_packages |
See documentation for |
y_col , pred_fun , pred_type |
See documentation for |
positive |
any single atomic value. If the model represented by |
boot_it |
non-negative integer(1). Number of bootstrap iterations for full-model bootstrapping. For bootstrapping of ALE values, see details to verify if |
boot_alpha |
numeric(1) from 0 to 1. Alpha for percentile-based confidence interval range for the bootstrap intervals; the bootstrap confidence intervals will be the lowest and highest |
boot_centre |
character(1) in c('mean', 'median'). When bootstrapping, the main estimate for the ALE y value is considered to be |
seed |
integer. Random seed. Supply this between runs to assure identical bootstrap samples are generated each time on the same data. See documentation for |
output_model_stats |
logical(1). If |
output_model_coefs |
logical(1). If |
output_ale |
logical(1). If |
output_boot_data |
logical(1). If |
ale_options , tidy_options , glance_options |
list of named arguments. Arguments to pass to the |
ale_p |
Same as the |
silent |
See documentation for |
An object of class ALE
with properties model_stats
, model_coefs
, ale
, model_stats
, boot_data
, and params
.
tibble
of bootstrapped results from broom::glance()
. NULL
if model_stats
argument is FALSE
. In general, only broom::glance()
results that make sense when bootstrapped are included, such as df
and adj.r.squared
. Results that are incomparable across bootstrapped datasets (such as aic
) are excluded. In addition, certain model performance measures are included; these are bootstrap-validated with the .632 correction (Efron & Tibshirani 1986) (NOT the .632+ correction):
For regression (numeric prediction) models:
mae
: mean absolute error (MAE)
sa_mae
: standardized accuracy of the MAE referenced on the mean absolute deviation
rmse
: root mean squared error (RMSE)
sa_rmse
: standardized accuracy of the RMSE referenced on the standard deviation
For binary or categorical classification (probability) models:
auc
: area under the ROC curve
A tibble
of bootstrapped results from broom::tidy()
.
NULL
if model_coefs
argument is FALSE
.
A list of bootstrapped ALE results using default ALE()
settings unless if overridden with ale_options
. NULL
if ale
argument is FALSE
. Elements are:
* `single`: an `ALE` object of ALE calculations on the full dataset without bootstrapping. * `boot`: a list of bootstrapped ALE data and statistics. This element is not an `ALE` object; it uses a special internal format.
A tibble
of bootstrap results. Each row represents a bootstrap iteration. NULL
if boot_data
argument is FALSE
. The columns are:
* `it`: the specific bootstrap iteration from 0 to `boot_it` iterations. Iteration 0 is the results from the full dataset (not bootstrapped). * `row_idxs`: the row indexes for the bootstrapped sample for that iteration. To save space, the row indexes are returned rather than the full datasets. So, for example, iteration i's bootstrap sample can be reproduced by `data[ModelBoot_obj@boot_data$row_idxs[[2]], ]` where `data` is the dataset and `ModelBoot_obj` is the result of `ModelBoot()`. * `model`: the model object trained on that iteration. * `ale`: the results of `ALE()` on that iteration. * `tidy`: the results of `broom::tidy(model)` on that iteration. * `stats`: the results of `broom::glance(model)` on that iteration. * `perf`: performance measures on the entire dataset. These are the measures specified above for regression and classification models.
Parameters used to calculate bootstrapped data. Most of these repeat the arguments passed to ModelBoot()
. These are either the values provided by the user or used by default if the user did not change them but the following additional objects created internally are also provided:
* `y_cats`: same as `ALE@params$y_cats` (see documentation there). * `y_type`: same as `ALE@params$y_type` (see documentation there). * `model`: same as `ALE@params$model` (see documentation there). * `data`: same as `ALE@params$data` (see documentation there).
No modelling results, with or without ALE, should be considered reliable without appropriate validation. For ALE, both the trained model itself and the ALE that explains the trained model must be validated. ALE must be validated by bootstrapping. The trained model might be validated either by cross-validation or by bootstrapping. For ALE that explains trained models that have been developed by cross-validation, it is sufficient to bootstrap just the training data. That is what the ALE
object does with its boot_it
argument. However, unvalidated models must be validated by bootstrapping them along with the calculation of ALE; this is what the ModelBoot
object does with its boot_it
argument.
ModelBoot()
carries out full-model bootstrapping to validate models. Specifically, it:
Creates multiple bootstrap samples (default 100; the user can specify any number);
Creates a model on each bootstrap sample;
Calculates overall model statistics, variable coefficients, and ALE values for each model on each bootstrap sample;
Calculates the mean, median, and lower and upper confidence intervals for each of those values across all bootstrap samples.
Okoli, Chitu. 2023. “Statistical Inference Using Machine Learning and Classical Techniques Based on Accumulated Local Effects (ALE).” arXiv. doi:10.48550/arXiv.2310.09877.<
Efron, Bradley, and Robert Tibshirani. "Bootstrap methods for standard errors, confidence intervals, and other measures of statistical accuracy." Statistical science (1986): 54-75. doi:10.1214/ss/1177013815
# attitude dataset
attitude
## ALE for generalized additive models (GAM)
## GAM is tweaked to work on the small dataset.
gam_attitude <- mgcv::gam(rating ~ complaints + privileges + s(learning) +
raises + s(critical) + advance,
data = attitude)
summary(gam_attitude)
# Full model bootstrapping
# Only 4 bootstrap iterations for a rapid example; default is 100
# Increase value of boot_it for more realistic results
mb_gam <- ModelBoot(
gam_attitude,
boot_it = 4
)
# If the model is not standard, supply model_call_string with 'data = boot_data'
# in the string instead of the actual dataset name (in addition to the actual dataset
# as the 'data' argument directly to the `ModelBoot` constructor).
mb_gam <- ModelBoot(
gam_attitude,
data = attitude, # the actual dataset
model_call_string = 'mgcv::gam(
rating ~ complaints + privileges + s(learning) +
raises + s(critical) + advance,
data = boot_data # required for model_call_string
)',
boot_it = 4
)
# Model statistics and coefficients
mb_gam@model_stats
mb_gam@model_coefs
# Plot ALE
plot(mb_gam)
# Retrieve ALE data
get(mb_gam, type = 'boot') # bootstrapped
get(mb_gam, type = 'single') # full (unbootstrapped) model
# See get.ALE() for other options
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.