class_docstr: Explains a model using expected gradients (an extension of integrated gradients).
  
  Expected gradients an extension of the integrated gradients method (Sundararajan et al. 2017), a
  feature attribution method designed for differentiable models based on an extension of Shapley
  values to infinite player games (Aumann-Shapley values). Integrated gradients values are a bit
  different from SHAP values, and require a single reference value to integrate from. As an adaptation
  to make them approximate SHAP values, expected gradients reformulates the integral as an expectation
  and combines that expectation with sampling reference values from the background dataset. This leads
  to a single combined expectation of gradients that converges to attributions that sum to the
  difference between the expected model output and the current output.
  
  Examples
  --------
  See :ref:`Gradient Explainer Examples <gradient_explainer_examples>`
docstr: An explainer object for a differentiable model using a given background dataset.
  
  Parameters
  ----------
  model : tf.keras.Model, (input : [tf.Tensor], output : tf.Tensor), torch.nn.Module, or a tuple
          (model, layer), where both are torch.nn.Module objects
  
      For TensorFlow this can be a model object, or a pair of TensorFlow tensors (or a list and
      a tensor) that specifies the input and output of the model to be explained. Note that for
      TensowFlow 2 you must pass a tensorflow function, not a tuple of input/output tensors).
  
      For PyTorch this can be a nn.Module object (model), or a tuple (model, layer), where both
      are nn.Module objects. The model is an nn.Module object which takes as input a tensor
      (or list of tensors) of shape data, and returns a single dimensional output. If the input
      is a tuple, the returned shap values will be for the input of the layer argument. layer must
      be a layer in the model, i.e. model.conv2.
  
  data : [numpy.array] or [pandas.DataFrame] or [torch.tensor]
      The background dataset to use for integrating out features. Gradient explainer integrates
      over these samples. The data passed here must match the input tensors given in the
      first argument. Single element lists can be passed unwrapped.
docstr_tok: ["An","explainer","object","for","a","differentiable","model","using","a","given","background","dataset",".","Parameters","--","--","--","--","--","model",":","tf.keras.Model",",","(","input",":","[","tf.Tensor","]",",","output",":","tf.Tensor",")",",","torch.nn.Module",",","or","a","tuple","(","model",",","layer",")",",","where","both","are","torch.nn.Module","objects","For","TensorFlow","this","can","be","a","model","object",",","or","a","pair","of","TensorFlow","tensors","(","or","a","list","and","a","tensor",")","that","specifies","the","input","and","output","of","the","model","to","be","explained",".","Note","that","for","TensowFlow","2","you","must","pass","a","tensorflow","function",",","not","a","tuple","of","input\/output","tensors",")",".","For","PyTorch","this","can","be","a","nn.Module","object","(","model",")",",","or","a","tuple","(","model",",","layer",")",",","where","both","are","nn.Module","objects",".","The","model","is","an","nn.Module","object","which","takes","as","input","a","tensor","(","or","list","of","tensors",")","of","shape","data",",","and","returns","a","single","dimensional","output",".","If","the","input","is","a","tuple",",","the","returned","shap","values","will","be","for","the","input","of","the","layer","argument",".","layer","must","be","a","layer","in","the","model",",","i.e",".","model.conv2",".","data",":","[","numpy.array","]","or","[","pandas.DataFrame","]","or","[","torch.tensor","]","The","background","dataset","to","use","for","integrating","out","features",".","Gradient","explainer","integrates","over","these","samples",".","The","data","passed","here","must","match","the","input","tensors","given","in","the","first","argument",".","Single","element","lists","can","be","passed","unwrapped","."]
code: def __init__(
      self, model, data, session=None, batch_size=50, local_smoothing=0
  ):
      """An explainer object for a differentiable model using a given background dataset.
  
      Parameters
      ----------
      model : tf.keras.Model, (input : [tf.Tensor], output : tf.Tensor), torch.nn.Module, or a tuple
              (model, layer), where both are torch.nn.Module objects
  
          For TensorFlow this can be a model object, or a pair of TensorFlow tensors (or a list and
          a tensor) that specifies the input and output of the model to be explained. Note that for
          TensowFlow 2 you must pass a tensorflow function, not a tuple of input/output tensors).
  
          For PyTorch this can be a nn.Module object (model), or a tuple (model, layer), where both
          are nn.Module objects. The model is an nn.Module object which takes as input a tensor
          (or list of tensors) of shape data, and returns a single dimensional output. If the input
          is a tuple, the returned shap values will be for the input of the layer argument. layer must
          be a layer in the model, i.e. model.conv2.
  
      data : [numpy.array] or [pandas.DataFrame] or [torch.tensor]
          The background dataset to use for integrating out features. Gradient explainer integrates
          over these samples. The data passed here must match the input tensors given in the
          first argument. Single element lists can be passed unwrapped.
      """
  
      # first, we need to find the framework
      if type(model) is tuple:
          a, b = model
          try:
              a.named_parameters()
              framework = "pytorch"
          except Exception:
              framework = "tensorflow"
      else:
          try:
              model.named_parameters()
              framework = "pytorch"
          except Exception:
              framework = "tensorflow"
  
      if isinstance(data, pd.DataFrame):
          self.features = data.columns.values
      else:
          self.features = None
  
      if framework == "tensorflow":
          self.explainer = _TFGradient(
              model, data, session, batch_size, local_smoothing
          )
      elif framework == "pytorch":
          self.explainer = _PyTorchGradient(
              model, data, batch_size, local_smoothing
          )
  
imports: import warnings
  import numpy
  import pandas
  from packaging import version
  from .._explanation import Explanation
  from ..explainers._explainer import Explainer
  from ..explainers.tf_utils import _get_graph, _get_model_inputs, _get_model_output, _get_session
label_desc: Use image node_id 1 to create a new GradientExplainer object from inherited base classes: Explainer with example: obj = GradientExplainer(model, data, session, batch_size, local_smoothing)