background is what the contributions are measured against, and most
estimators cannot work without one. A contribution says how far a feature
moved this case's prediction away from E[f(x)], and that expectation is a
property of the background data, and the model does not store the data it
was trained on. Pass the training features, or a
representative sample of them. The exceptions are the estimators that take
their baseline from the model itself, such as the LightGBM family's; those
ignore it, and everything else aborts without it.
Two explanations of one model against different backgrounds are not
comparable. The result carries a fingerprint of the background it used.
config chooses the method, built by setup_SHAP:
setup_SHAP(perturbation = "conditional") picks the value function,
setup_SHAP(estimator = "kernel") overrides the estimator the algorithm
would otherwise get. explanation_traits reports which estimator applies to
which algorithm, whether it is exact, and why.
A SupervisedRes additionally takes type: "avg" (the default) averages
the resamples' explanations, which decomposes the averaged prediction
exactly, and "all" returns one explanation per resample.
The contributions plus the baseline reconstruct the prediction exactly, on
the scale they were computed on. For classification that scale is the
model's margin, not the probability stats::predict() returns:
probability is a nonlinear transform of the margin, so contributions do not
sum to it.
Read the result with shap_case for one case, shap_long across cases,
shap_by_level for the levels of a categorical, and get_varimp() for
mean(|phi|) per feature.
A SHAP value is not a causal effect. It attributes a prediction under the
model's own logic; intervening on a feature in the world does not move the
outcome by its attribution. Correlated features split credit between
themselves, and how they split it depends on the value function -- so a small
attribution does not show a feature to be unimportant, and this is not a
feature-selection criterion.