View source: R/model_performance_bootstrap_rmse.R
| bootstrap_performance | R Documentation |
Generate repeated train/evaluation samples to compute model performance. Currently, the supported metric is root mean squared error (RMSE).
bootstrap_performance(
model,
data,
n_resamples = 50,
sample_fraction = 1,
metric = "rmse",
sampling = c("bootstrap", "split"),
show_progress = TRUE,
rmse_model = NULL,
n = NULL,
frac = NULL
)
model |
A fitted model object. |
data |
Data used to fit the model object. |
n_resamples |
Integer. Number of resampling replicates. Default = 50. |
sample_fraction |
Fraction of the data used in the training sample. Must
be in |
metric |
Character. Performance metric to compute. Currently only
|
sampling |
Character. Sampling scheme. |
show_progress |
Logical. Show progress bar during bootstrap iterations. Default = TRUE. |
rmse_model |
Optional numeric RMSE of the fitted (original) model. If NULL (default), it is computed automatically. |
n, frac |
Deprecated argument names. Use |
To test the predictive stability of a fitted model it can be helpful to assess the variation in a performance metric. The variation is calculated by refitting the model on repeated samples and storing the resulting metric values.
If sample_fraction = 1, the metric is evaluated on the sampled training
data.
If sample_fraction < 1, the metric is evaluated on rows that were not
used for training.
Character columns and factor columns are converted to factors with levels taken from the full input data before resampling. For factor variables used in the model, the training sample is augmented when needed so every observed level is represented at least once. This prevents prediction failures when a level is present in the evaluation data but absent from a particular training sample.
An object of class "bootstrap_performance", which is a list with components:
Numeric vector with n_resamples bootstrap RMSE values.
Root mean squared error for the original fitted model.
Metric name.
Sampling scheme.
Martin Haringa
## Not run:
mod1 <- glm(nclaims ~ age_policyholder, data = MTPL,
offset = log(exposure), family = poisson())
# Use all records
x <- bootstrap_performance(mod1, MTPL, n_resamples = 80,
show_progress = FALSE)
print(x)
autoplot(x)
# Use 80% of records and evaluate on the remaining records
x_frac <- bootstrap_performance(mod1, MTPL, n_resamples = 50,
sample_fraction = .8, sampling = "split",
show_progress = FALSE)
autoplot(x_frac)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.