class_docstr: Computes SHAP values using an extension of the Shapley sampling values explanation method
  (also known as IME).
  
  SamplingExplainer computes SHAP values under the assumption of feature independence and is an
  extension of the algorithm proposed in "An Efficient Explanation of Individual Classifications
  using Game Theory", Erik Strumbelj, Igor Kononenko, JMLR 2010. It is a good alternative to
  KernelExplainer when you want to use a large background set (as opposed to a single reference
  value for example).
  
  Parameters
  ----------
  model : function
      User supplied function that takes a matrix of samples (# samples x # features) and
      computes the output of the model for those samples. The output can be a vector
      (# samples) or a matrix (# samples x # model outputs).
  
  data : numpy.array or pandas.DataFrame
      The background dataset to use for integrating out features. To determine the impact
      of a feature, that feature is set to "missing" and the change in the model output
      is observed. Since most models aren't designed to handle arbitrary missing data at test
      time, we simulate "missing" by replacing the feature with the values it takes in the
      background dataset. So if the background dataset is a simple sample of all zeros, then
      we would approximate a feature being missing by setting it to zero. Unlike the
      KernelExplainer, this data can be the whole training set, even if that is a large set. This
      is because SamplingExplainer only samples from this background dataset.
class_docstr_tok: ["Computes","SHAP","values","using","an","extension","of","the","Shapley","sampling","values","explanation","method","(","also","known","as","IME",")",".","SamplingExplainer","computes","SHAP","values","under","the","assumption","of","feature","independence","and","is","an","extension","of","the","algorithm","proposed","in","``","An","Efficient","Explanation","of","Individual","Classifications","using","Game","Theory","''",",","Erik","Strumbelj",",","Igor","Kononenko",",","JMLR","2010",".","It","is","a","good","alternative","to","KernelExplainer","when","you","want","to","use","a","large","background","set","(","as","opposed","to","a","single","reference","value","for","example",")",".","Parameters","--","--","--","--","--","model",":","function","User","supplied","function","that","takes","a","matrix","of","samples","(","#","samples","x","#","features",")","and","computes","the","output","of","the","model","for","those","samples",".","The","output","can","be","a","vector","(","#","samples",")","or","a","matrix","(","#","samples","x","#","model","outputs",")",".","data",":","numpy.array","or","pandas.DataFrame","The","background","dataset","to","use","for","integrating","out","features",".","To","determine","the","impact","of","a","feature",",","that","feature","is","set","to","``","missing","''","and","the","change","in","the","model","output","is","observed",".","Since","most","models","are","n't","designed","to","handle","arbitrary","missing","data","at","test","time",",","we","simulate","``","missing","''","by","replacing","the","feature","with","the","values","it","takes","in","the","background","dataset",".","So","if","the","background","dataset","is","a","simple","sample","of","all","zeros",",","then","we","would","approximate","a","feature","being","missing","by","setting","it","to","zero",".","Unlike","the","KernelExplainer",",","this","data","can","be","the","whole","training","set",",","even","if","that","is","a","large","set",".","This","is","because","SamplingExplainer","only","samples","from","this","background","dataset","."]
code: def sampling_estimate(self, j, f, x, X, nsamples=10):
      X_masked = self.X_masked[: nsamples * 2, :]
      inds = np.arange(X.shape[1])
  
      for i in range(0, nsamples):
          np.random.shuffle(inds)
          pos = np.where(inds == j)[0][0]
          rind = np.random.randint(X.shape[0])
          X_masked[i, :] = x
          X_masked[i, inds[pos + 1 :]] = X[rind, inds[pos + 1 :]]
          X_masked[-(i + 1), :] = x
          X_masked[-(i + 1), inds[pos:]] = X[rind, inds[pos:]]
  
      evals = f(X_masked)
      evals_on = evals[:nsamples]
      evals_off = evals[nsamples:][::-1]
      d = evals_on - evals_off
  
      return np.mean(d, 0), np.var(d, 0)
  
file_path: shap/shap/explainers/_sampling.py
imports: import logging
  import numpy
  import pandas
  from .._explanation import Explanation
  from ..utils._exceptions import ExplainerError
  from ..utils._legacy import convert_to_instance, match_instance_to_data
  from ._kernel import KernelExplainer
label_desc: Use image node_id 4 for calling the SamplingExplainer obj's underlying member method code with example usage: obj.sampling_estimate(j, f, x, X, nsamples) and returns: np,  np