| pred_nestcv_glmnet | R Documentation |
Prediction wrapper functions to enable the use of the shapr package for
generating SHAP values from nestedcv trained models.
pred_nestcv_glmnet(x, newdata)
pred_nestcv_glmnet_class(cl)
pred_train(x, newdata)
pred_train_class(cl)
pred_SuperLearner(x, newdata)
x |
a |
newdata |
a matrix or data frame of new data |
cl |
integer representing which class to predict |
These prediction wrapper functions are designed to be used with the
shapr package via nestcv.explain(). The functions
pred_nestcv_glmnet and pred_train work for nestcv.glmnet and
nestcv.train models respectively for either binary classification or
regression.
For multiclass classification use pred_nestcv_glmnet_class(1),
pred_nestcv_glmnet_class(2) etc for each class. Similarly
pred_train_class(1), pred_train_class(2) etc for nestcv.train
objects.
prediction wrapper function designed for use with
nestcv.explain() or shapr::explain()
if (requireNamespace("shapr") & requireNamespace("mlbench")) {
library(shapr)
# Boston housing dataset
library(mlbench)
data(BostonHousing2)
dat <- BostonHousing2
y <- dat$cmedv
x <- subset(dat, select = -c(cmedv, medv, town, chas))
# Fit a glmnet model using nested CV
# Only 3 outer CV folds and 1 alpha value for speed
fit <- nestcv.glmnet(y, x, family = "gaussian", n_outer_folds = 3, alphaSet = 1)
# Generate SHAP values using shapr
sh <- nestcv.explain(fit, pred_nestcv_glmnet)
# Plot overall variable importance
plot_shap_bar(sh, x)
# Plot beeswarm plot
plot_shap_beeswarm(sh, x, size = 1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.