shap.utils.sample
- shap.utils.sample(X: _ArrayT, nsamples: int = 100, random_state: int = 0) _ArrayT
Performs sampling without replacement of the input data
X.This is a simple wrapper over scikit-learn’s
shufflefunction. It is used mainly to downsampleXfor use as a background dataset in SHAPExplainerand its subclasses.Changed in version 0.42: The behaviour of
samplewas changed from sampling with replacement to sampling without replacement. Note that reproducibility might be broken when using this function pre- and post-0.42, even with the specification ofrandom_state.- Parameters:
- Xarray-like
Data to sample from. Input data can be arrays, lists, dataframes or scipy sparse matrices with a consistent first dimension.
- nsamplesint
Number of samples to generate from
X.- random_state
Determines random number generation for shuffling the data. Use this to ensure reproducibility across multiple function calls.