code: def expected_gradients(model, data):
      
      if isinstance(model, KerasWrap):
          model = model.model
      explainer = GradientExplainer(model, data)
      def f(X):
          phi = explainer.shap_values(X)
          if type(phi) is list and len(phi) == 1:
              return phi[0]
          else:
              return phi
      
      return f
docs: Expected Gradients