I am learning SHAP, and have this quick question. If kernel SHAP values are estimated by randomly sampling feature values, why every time I received exactly the same SHAP values for the same model?
Any comments are very well appreciated. Thank you in advance.
If the number of features p is not too large, then Kernel SHAP is deterministic. This can be seen by studying Scott Lundberg's KernelExplainer code.
The shap_values()
method of KernelExplainer
has an argument nsamples
with default "auto" set to 2^11 + 2p. Since Kernel SHAP requires at most 2^p - 2 different "on-off" vectors (and since Scott is very smart), your results will be exact for the selected background data up to p = 11 features.
In case p is > 11 (and you don't fiddle with the defaults), the impact of the random part is often negligible. Thus, even for larger p, the algorithm often looks as being deterministic.