Convenience wrapper around shapr::explain() that works with nestedcv
fitted models. Returns the shapr object directly, compatible with
plot_shap_bar(), plot_shap_beeswarm(), and shapr's own print()/
plot() methods.
nestcv.explain(
model,
predict_model,
x_explain = x_train,
x_train = NULL,
approach = "independence",
phi0 = NULL,
...
)the shapr object returned by shapr::explain(). Pass it
directly to plot_shap_bar() or plot_shap_beeswarm(), or use
shapr's own print()/plot() methods on it.
A nestcv.glmnet, nestcv.train, or other nestedcv model
object.
Prediction wrapper function with signature
function(model, newdata) returning a numeric vector of predictions.
Use pred_nestcv_glmnet(), pred_train(), pred_nestcv_glmnet_class(),
pred_train_class(), or pred_SuperLearner() as appropriate.
A matrix or data frame of feature values to compute SHAP
values for. Defaults to x_train.
A matrix or data frame of feature values used as the
background training data. Defaults to the original training data from
model, which is stored as model$xsub[, model$final_vars] for fitted
nestcv.glmnet/nestcv.train). Or users can supply their own training
data.
Character string specifying the shapr estimation approach.
Defaults to "independence", which is the original method by Lundberg and
is faster than other methods. The makers of shapr recommend "gaussian"
for multivariate gaussian data or "empirical" as the main regression
methods, i.e. if all x is numeric. For other approaches, see
shapr::explain().
Numeric scalar; the baseline (null) prediction (i.e. the
expected model output when no features are known). Defaults to NULL, in
which case it is automatically computed as mean(model$y) or
mean(predict_model(model, x_explain)) on supplied data for
classification. For regression this equals mean(y_train); for
classification it equals the mean predicted probability. Override this
argument if you want to use a different reference value, e.g. computed on a
held-out set.
Additional arguments passed to shapr::explain(), e.g.
verbose.