Description Usage Arguments Value Author(s) Examples
Create an explainer object with Shapley weights for test data.
1 
x 
Numeric matrix or data.frame/data.table. Contains the data used to estimate the (conditional) distributions for the features needed to properly estimate the conditional expectations in the Shapley formula. 
model 
The model whose predictions we want to explain. Run

n_combinations 
Integer. The number of feature combinations to sample. If 
Named list that contains the following items:
Boolean. Equals TRUE
if n_combinations = NULL
or
n_combinations < 2^ncol(x)
, otherwise FALSE
.
Positive integer. The number of columns in x
Binary matrix. The number of rows equals the number of unique combinations, and
the number of columns equals the total number of features. I.e. let's say we have a case with
three features. In that case we have 2^3 = 8
unique combinations. If the jth
observation for the ith row equals 1
it indicates that the jth feature is present in
the ith combination. Otherwise it equals 0
.
Second item
data.table. Returned object from feature_combinations
data.table. Transformed x
into a data.table.
List. The updated_feature_list
output from
preprocess_data
In addition to the items above, model
and n_combinations
are also present in the returned object.
Nikolai Sellereite
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  if (requireNamespace("MASS", quietly = TRUE)) {
# Load example data
data("Boston", package = "MASS")
df < Boston
# Example using the exact method
x_var < c("lstat", "rm", "dis", "indus")
y_var < "medv"
df1 < df[, x_var]
model < lm(medv ~ lstat + rm + dis + indus, data = df)
explainer < shapr(df1, model)
print(nrow(explainer$X))
# 16 (which equals 2^4)
# Example using approximation
y_var < "medv"
x_var < setdiff(colnames(df), y_var)
model < lm(medv ~ ., data = df)
df2 < df[, x_var]
explainer < shapr(df2, model, n_combinations = 1e3)
print(nrow(explainer$X))
# Example using approximation where n_combinations > 2^m
x_var < c("lstat", "rm", "dis", "indus")
y_var < "medv"
df3 < df[, x_var]
model < lm(medv ~ lstat + rm + dis + indus, data = df)
explainer < shapr(df1, model, n_combinations = 1e3)
print(nrow(explainer$X))
# 16 (which equals 2^4)
}

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.