| prediction {shapr} | R Documentation |
Calculate Shapley weights for test data
Description
This function should only be called internally, and not be used as a stand-alone function.
Usage
prediction(dt, prediction_zero, explainer)
Arguments
dt |
data.table |
prediction_zero |
Numeric. The value to use for |
explainer |
An object of class |
Details
If dt does not contain three columns called id, id_combination and w
the function will fail. id represents a unique key for a given test observation,
and id_combination is a unique key for which feature combination the row represents. w
represents the Shapley value of feature combination given by id_combination. In addition
to these three columns, dt should also have columns which matches the variables used
when training the model.
I.e. you have fitted a linear model using the features x1,
x2 and x3, and you want to explain 5 test observations using the exact method, i.e.
setting exact = TRUE in shapr, the following properties should be satisfied
-
colnames(dt)equalsc("x1", "x2", "x3", "id", "id_combination", ""w) -
dt[, max(id)]equals the number of test observations -
dt[, min(id)]equals 1L. -
dt[, max(id_combination)]equals2^mwhere m equals the number of features. -
dt[, min(id_combination)]equals 1L. -
dt[, type(w)]equalsdouble.
Value
An object of class c("shapr", "list"). For more details see explain.
Author(s)
Nikolai Sellereite