code: def unpack_kwargs_lime(explainer, new_observation, **kwargs):
      # utility function for predict_surrogate(type='lime')
      # use https://stackoverflow.com/a/58543357 to unpack the **kwargs into multiple functions
      from lime.lime_tabular import LimeTabularExplainer
  
      explainer_args = [
          k
          for k, v in inspect.signature(
              LimeTabularExplainer
          ).parameters.items()
      ]
      explainer_dict = {
          k: kwargs.pop(k) for k in dict(kwargs) if k in explainer_args
      }
      explanation_args = [
          k
          for k, v in inspect.signature(
              LimeTabularExplainer.explain_instance
          ).parameters.items()
      ]
      explanation_dict = {
          k: kwargs.pop(k)
          for k in dict(kwargs)
          if k in explanation_args
      }
  
      if "training_data" not in explainer_dict:
          explainer_dict["training_data"] = explainer.data.to_numpy()
      if "mode" not in explainer_dict:
          explainer_dict["mode"] = explainer.model_type
      if "feature_names" not in explainer_dict:
          explainer_dict["feature_names"] = explainer.data.columns
      if "data_row" not in explanation_dict:
          explanation_dict["data_row"] = new_observation
      if "predict_fn" not in explanation_dict:
          if explainer_dict["mode"] == "regression":
              explanation_dict[
                  "predict_fn"
              ] = lambda x: explainer.predict(
                  pd.DataFrame(x, columns=explainer.data.columns)
              )
          elif explainer_dict["mode"] == "classification":
              explanation_dict["predict_fn"] = lambda x: np.concatenate(
                  [
                      1
                      - explainer.predict(
                          pd.DataFrame(
                              x, columns=explainer.data.columns
                          )
                      ).reshape(-1, 1),
                      explainer.predict(
                          pd.DataFrame(
                              x, columns=explainer.data.columns
                          )
                      ).reshape(-1, 1),
                  ],
                  axis=1,
              )
          else:
              raise ValueError(
                  "Pass a 'mode' parameter to the `predict_surrogate` method. "
                  "See https://lime-ml.readthedocs.io/en/latest/lime.html#lime.lime_tabular.LimeTabularExplainer"
              )
          try:
              explanation_dict["predict_fn"](
                  explainer_dict["training_data"]
              )
          except:
              raise ValueError(
                  "Pass a proper `predict_fn` parameter to the `predict_surrogate` method. "
                  "See https://lime-ml.readthedocs.io/en/latest/lime.html#lime.lime_tabular.LimeTabularExplainer.explain_instance"
              )
      return explainer_dict, explanation_dict
  
file_path: DALEX/python/dalex/dalex/_explainer/utils.py
imports: import numpy
  import pandas
  import types, inspect, warnings
label_desc: Use image node_id 2 for calling a global function with example usage: unpack_kwargs_lime(explainer, new_observation) and returns: explainer_dict,  explanation_dict