| shap | R Documentation |
This function computes the marginal (interaction) SHAP values for a prediction rule ensemble as fitted with function
pre.
shap(
object,
newdata = NULL,
reference_data = NULL,
penalty.par.val = "lambda.1se",
interactions = FALSE,
block_size = 5000,
...
)
object |
object of class |
newdata |
An optional |
reference_data |
An optional |
penalty.par.val |
character or numeric. Value of the penalty parameter
|
interactions |
A logical value indicating whether marginal interaction SHAP values should be computed, on top of the overall values. |
block_size |
Computation of SHAP values involves computations on large matrices. For computational reasons, these are split into small submatrices. This integer denotes the number of rows of the submatrix. |
... |
Further arguments to be passed to |
Adapted code from original written by and used with permission from Giorgio Spadaccini.
A list with two objects:
marginal An $N$ by $p$ matrix with SHAP values for each observation (rows) and predictor (columns),
with rownames corresponding to rownames(newdata).
interactions A $p$ by $p$ by $N$ array with SHAP interaction values. Each slice contains a
$p /times p$ symmetric matrix, of which the diagonal entries present the predictor
variables' main effect SHAP values and the off-diagonal entries represent their interaction SHAP values.
All SHAP values are on the scale of the linear predictor.
Giorgio Spadaccini
#' @seealso print.pre, plot.pre,
coef.pre, importance.pre, predict.pre,
interact, cvpre
## Fit pre, then compute SHAP values for the first 10 training observations
airq <- airquality[complete.cases(airquality), ]
set.seed(42)
airq.ens <- pre(Ozone ~ ., data = airq)
airq.shap <- shap(airq.ens, newdata = airq[1:10, ])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.