pred_nestcv_glmnet | R Documentation |
Prediction wrapper functions to enable the use of the fastshap
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 of new data |
cl |
integer representing which class to predict |
These prediction wrapper functions are designed to be used with the
fastshap
package. 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
fastshap::explain()
library(fastshap)
# 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 fastshap::explain
# Only using 5 repeats here for speed, but recommend higher values of nsim
sh <- explain(fit, X=x, pred_wrapper = pred_nestcv_glmnet, nsim = 1)
# 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.