Configure per-case Shapley additive explanations for explain().
Usage
setup_SHAP(
estimator = "auto",
perturbation = NULL,
scale = NULL,
background_n = NULL,
n_coalitions = NULL,
approach = NULL,
seed = NULL
)Arguments
- estimator
Character {"auto", "exact", "kernel"}: Which estimator to use.
- perturbation
Optional Character {"interventional", "conditional"}: Value function. NULL uses the resolved estimator's documented default.
- scale
Optional Character {"margin", "probability"}: Scale the contributions are additive on. NULL sets it from the outcome type.
- background_n
Optional Integer [1, Inf): Cases to subsample from the background data. NULL uses all of it.
- n_coalitions
Optional Integer [2, Inf): Most feature subsets the kernel estimator evaluates. NULL lets the backend decide.
- approach
Optional Character {"empirical", "gaussian", "copula", "ctree", "vaeac", "categorical", "timeseries"}: Conditional-distribution estimator used by the kernel estimator.
- seed
Optional Integer [0, Inf): Random seed.
Details
Three choices here define what is computed, and each is recorded on the returned explanation, so explanations computed differently are told apart.
perturbation is the question being asked. "interventional" breaks the
dependence between features, attributing to what the model uses: a feature
the model ignores gets zero even if it predicts the outcome perfectly.
"conditional" respects the joint distribution, attributing to what the
case's features tell you, so a correlated proxy for a used feature receives
credit. Neither is the correct one – debugging a model wants the first,
reasoning about a subject wants the second.
scale decides whether the contributions add up. They are additive on
the scale they are computed on. For regression that is the outcome and there
is nothing to choose. For classification the model's additive scale is the
margin, and probability is a nonlinear transform of it, so contributions on
the probability scale do not sum to the predicted probability.
estimator is normally best left alone. "auto" uses the exact
estimator wherever the algorithm has one and the model-agnostic kernel
estimator otherwise; explanation_methods() reports which applies where.
approach and n_coalitions apply only to the kernel estimator, and
approach only when perturbation is "conditional" – the interventional
answer is not one of several conditional estimators, it is the absence of
conditioning.
Setting either therefore requires estimator = "kernel" rather than
"auto", even for an algorithm "auto" would send to the kernel estimator
anyway. Tuning an estimator is a decision to use it, and the alternative –
accepting settings that a resolved exact estimator would then ignore –
would drop them silently.
Examples
setup_SHAP()#> <SHAPConfig>
#> estimator: auto
#> perturbation: NULL
#> scale: NULL
#> background_n: NULL
#> n_coalitions: NULL
#> approach: NULL
#> seed: NULLsetup_SHAP(perturbation = "conditional")#> <SHAPConfig>
#> estimator: auto
#> perturbation: conditional
#> scale: NULL
#> background_n: NULL
#> n_coalitions: NULL
#> approach: NULL
#> seed: NULLsetup_SHAP(estimator = "kernel", perturbation = "conditional", approach = "ctree")#> <SHAPConfig>
#> estimator: kernel
#> perturbation: conditional
#> scale: NULL
#> background_n: NULL
#> n_coalitions: NULL
#> approach: ctree
#> seed: NULL