class_docstr: Uses the Kernel SHAP method to explain the output of any function.
  
  Kernel SHAP is a method that uses a special weighted linear regression
  to compute the importance of each feature. The computed importance values
  are Shapley values from game theory and also coefficients from a local linear
  regression.
  
  Parameters
  ----------
  model : function or iml.Model
      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 or shap.common.DenseData or any scipy.sparse matrix
      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. For small problems,
      this background dataset can be the whole training set, but for larger problems consider
      using a single reference value or using the ``kmeans`` function to summarize the dataset.
      Note: for the sparse case, we accept any sparse matrix but convert to lil format for
      performance.
  
  feature_names : list
      The names of the features in the background dataset. If the background dataset is
      supplied as a pandas.DataFrame, then ``feature_names`` can be set to ``None`` (default),
      and the feature names will be taken as the column names of the dataframe.
  
  link : "identity" or "logit"
      A generalized linear model link to connect the feature importance values to the model
      output. Since the feature importance values, phi, sum up to the model output, it often makes
      sense to connect them to the output with a link function where link(output) = sum(phi).
      Default is "identity" (a no-op).
      If the model output is a probability, then "logit" can be used to transform the SHAP values
      into log-odds units.
  
  Examples
  --------
  See :ref:`Kernel Explainer Examples <kernel_explainer_examples>`.
class_docstr_tok: ["Uses","the","Kernel","SHAP","method","to","explain","the","output","of","any","function",".","Kernel","SHAP","is","a","method","that","uses","a","special","weighted","linear","regression","to","compute","the","importance","of","each","feature",".","The","computed","importance","values","are","Shapley","values","from","game","theory","and","also","coefficients","from","a","local","linear","regression",".","Parameters","--","--","--","--","--","model",":","function","or","iml.Model","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","or","shap.common.DenseData","or","any","scipy.sparse","matrix","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",".","For","small","problems",",","this","background","dataset","can","be","the","whole","training","set",",","but","for","larger","problems","consider","using","a","single","reference","value","or","using","the","``","kmeans","``","function","to","summarize","the","dataset",".","Note",":","for","the","sparse","case",",","we","accept","any","sparse","matrix","but","convert","to","lil","format","for","performance",".","feature_names",":","list","The","names","of","the","features","in","the","background","dataset",".","If","the","background","dataset","is","supplied","as","a","pandas.DataFrame",",","then","``","feature_names","``","can","be","set","to","``","None","``","(","default",")",",","and","the","feature","names","will","be","taken","as","the","column","names","of","the","dataframe",".","link",":","``","identity","''","or","``","logit","''","A","generalized","linear","model","link","to","connect","the","feature","importance","values","to","the","model","output",".","Since","the","feature","importance","values",",","phi",",","sum","up","to","the","model","output",",","it","often","makes","sense","to","connect","them","to","the","output","with","a","link","function","where","link","(","output",")","=","sum","(","phi",")",".","Default","is","``","identity","''","(","a","no-op",")",".","If","the","model","output","is","a","probability",",","then","``","logit","''","can","be","used","to","transform","the","SHAP","values","into","log-odds","units",".","Examples","--","--","--","--","See",":","ref",":","`","Kernel","Explainer","Examples","<","kernel_explainer_examples",">","`","."]
docstr: Estimate the SHAP values for a set of samples.
  
  Parameters
  ----------
  X : numpy.array or pandas.DataFrame or any scipy.sparse matrix
      A matrix of samples (# samples x # features) on which to explain the model's output.
  
  nsamples : "auto" or int
      Number of times to re-evaluate the model when explaining each prediction. More samples
      lead to lower variance estimates of the SHAP values. The "auto" setting uses
      `nsamples = 2 * X.shape[1] + 2048`.
  
  l1_reg : "num_features(int)", "auto" (default for now, but deprecated), "aic", "bic", or float
      The l1 regularization to use for feature selection (the estimation procedure is based on
      a debiased lasso). The auto option currently uses "aic" when less that 20% of the possible sample
      space is enumerated, otherwise it uses no regularization. THE BEHAVIOR OF "auto" WILL CHANGE
      in a future version to be based on num_features instead of AIC.
      The "aic" and "bic" options use the AIC and BIC rules for regularization.
      Using "num_features(int)" selects a fix number of top features. Passing a float directly sets the
      "alpha" parameter of the sklearn.linear_model.Lasso model used for feature selection.
  
  gc_collect : bool
     Run garbage collection after each explanation round. Sometime needed for memory intensive explanations (default False).
  
  Returns
  -------
  array or list
      For models with a single output this returns a matrix of SHAP values
      (# samples x # features). Each row sums to the difference between the model output for that
      sample and the expected value of the model output (which is stored as expected_value
      attribute of the explainer). For models with vector outputs this returns a list
      of such matrices, one for each output.
docstr_tok: ["Estimate","the","SHAP","values","for","a","set","of","samples",".","Parameters","--","--","--","--","--","X",":","numpy.array","or","pandas.DataFrame","or","any","scipy.sparse","matrix","A","matrix","of","samples","(","#","samples","x","#","features",")","on","which","to","explain","the","model","'s","output",".","nsamples",":","``","auto","''","or","int","Number","of","times","to","re-evaluate","the","model","when","explaining","each","prediction",".","More","samples","lead","to","lower","variance","estimates","of","the","SHAP","values",".","The","``","auto","''","setting","uses","`","nsamples","=","2","*","X.shape","[","1","]","+","2048","`",".","l1_reg",":","``","num_features","(","int",")","''",",","``","auto","''","(","default","for","now",",","but","deprecated",")",",","``","aic","''",",","``","bic","''",",","or","float","The","l1","regularization","to","use","for","feature","selection","(","the","estimation","procedure","is","based","on","a","debiased","lasso",")",".","The","auto","option","currently","uses","``","aic","''","when","less","that","20","%","of","the","possible","sample","space","is","enumerated",",","otherwise","it","uses","no","regularization",".","THE","BEHAVIOR","OF","``","auto","''","WILL","CHANGE","in","a","future","version","to","be","based","on","num_features","instead","of","AIC",".","The","``","aic","''","and","``","bic","''","options","use","the","AIC","and","BIC","rules","for","regularization",".","Using","``","num_features","(","int",")","''","selects","a","fix","number","of","top","features",".","Passing","a","float","directly","sets","the","``","alpha","''","parameter","of","the","sklearn.linear_model.Lasso","model","used","for","feature","selection",".","gc_collect",":","bool","Run","garbage","collection","after","each","explanation","round",".","Sometime","needed","for","memory","intensive","explanations","(","default","False",")",".","Returns","--","--","--","-","array","or","list","For","models","with","a","single","output","this","returns","a","matrix","of","SHAP","values","(","#","samples","x","#","features",")",".","Each","row","sums","to","the","difference","between","the","model","output","for","that","sample","and","the","expected","value","of","the","model","output","(","which","is","stored","as","expected_value","attribute","of","the","explainer",")",".","For","models","with","vector","outputs","this","returns","a","list","of","such","matrices",",","one","for","each","output","."]
code: def shap_values(self, X, **kwargs):
      """Estimate the SHAP values for a set of samples.
  
      Parameters
      ----------
      X : numpy.array or pandas.DataFrame or any scipy.sparse matrix
          A matrix of samples (# samples x # features) on which to explain the model's output.
  
      nsamples : "auto" or int
          Number of times to re-evaluate the model when explaining each prediction. More samples
          lead to lower variance estimates of the SHAP values. The "auto" setting uses
          `nsamples = 2 * X.shape[1] + 2048`.
  
      l1_reg : "num_features(int)", "auto" (default for now, but deprecated), "aic", "bic", or float
          The l1 regularization to use for feature selection (the estimation procedure is based on
          a debiased lasso). The auto option currently uses "aic" when less that 20% of the possible sample
          space is enumerated, otherwise it uses no regularization. THE BEHAVIOR OF "auto" WILL CHANGE
          in a future version to be based on num_features instead of AIC.
          The "aic" and "bic" options use the AIC and BIC rules for regularization.
          Using "num_features(int)" selects a fix number of top features. Passing a float directly sets the
          "alpha" parameter of the sklearn.linear_model.Lasso model used for feature selection.
  
      gc_collect : bool
         Run garbage collection after each explanation round. Sometime needed for memory intensive explanations (default False).
  
      Returns
      -------
      array or list
          For models with a single output this returns a matrix of SHAP values
          (# samples x # features). Each row sums to the difference between the model output for that
          sample and the expected value of the model output (which is stored as expected_value
          attribute of the explainer). For models with vector outputs this returns a list
          of such matrices, one for each output.
      """
  
      # convert dataframes
      if isinstance(X, pd.Series):
          X = X.values
      elif isinstance(X, pd.DataFrame):
          if self.keep_index:
              index_value = X.index.values
              index_name = X.index.name
              column_name = list(X.columns)
          X = X.values
  
      x_type = str(type(X))
      arr_type = "'numpy.ndarray'>"
      # if sparse, convert to lil for performance
      if scipy.sparse.issparse(X) and not scipy.sparse.isspmatrix_lil(
          X
      ):
          X = X.tolil()
      assert x_type.endswith(arr_type) or scipy.sparse.isspmatrix_lil(
          X
      ), ("Unknown instance type: " + x_type)
  
      # single instance
      if len(X.shape) == 1:
          data = X.reshape((1, X.shape[0]))
          if self.keep_index:
              data = convert_to_instance_with_index(
                  data, column_name, index_name, index_value
              )
          explanation = self.explain(data, **kwargs)
  
          # vector-output
          s = explanation.shape
          if len(s) == 2:
              outs = [np.zeros(s[0]) for j in range(s[1])]
              for j in range(s[1]):
                  outs[j] = explanation[:, j]
              return outs
  
          # single-output
          else:
              out = np.zeros(s[0])
              out[:] = explanation
              return out
  
      # explain the whole dataset
      elif len(X.shape) == 2:
          explanations = []
          for i in tqdm(
              range(X.shape[0]), disable=kwargs.get("silent", False)
          ):
              data = X[i : i + 1, :]
              if self.keep_index:
                  data = convert_to_instance_with_index(
                      data,
                      column_name,
                      index_value[i : i + 1],
                      index_name,
                  )
              explanations.append(self.explain(data, **kwargs))
              if kwargs.get("gc_collect", False):
                  gc.collect()
  
          # vector-output
          s = explanations[0].shape
          if len(s) == 2:
              outs = [np.zeros((X.shape[0], s[0])) for j in range(s[1])]
              for i in range(X.shape[0]):
                  for j in range(s[1]):
                      outs[j][i] = explanations[i][:, j]
              return outs
  
          # single-output
          else:
              out = np.zeros((X.shape[0], s[0]))
              for i in range(X.shape[0]):
                  out[i] = explanations[i]
              return out
  
      else:
          emsg = "Instance must have 1 or 2 dimensions!"
          raise DimensionError(emsg)
  
imports: import copy
  import gc
  import itertools
  import logging
  import time
  import warnings
  import numpy
  import pandas
  import scipy.sparse
  import sklearn
  from packaging import version
  from scipy.special import binom
  from sklearn.linear_model import Lasso, LassoLarsIC, lars_path
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import StandardScaler
  from tqdm.auto import tqdm
  from .._explanation import Explanation
  from ..utils import safe_isinstance
  from ..utils._exceptions import DimensionError
  from ..utils._legacy import DenseData, SparseData, convert_to_data, convert_to_instance, convert_to_instance_with_index, convert_to_link, convert_to_model, match_instance_to_data, match_model_to_data
  from ._explainer import Explainer
label_desc: Use image node_id 3 for calling the KernelExplainer obj's underlying member method code with example usage: obj.shap_values(X) and returns: outs, out, outs, out