class_docstr: Create Model Explainer
  
  Black-box models may have very different structures. This class creates a unified
  representation of a model, which can be further processed by various explanations.
  Methods of this class produce explanation objects, that contain the main result
  attribute, and can be visualised using the plot method.
  
  The `model` is the only required parameter, but most of the explanations require
  that other parameters are provided (See `data`, `y`, `predict_function`, `model_type`).
  
  Parameters
  ----------
  model : object
      Model to be explained.
  data : pd.DataFrame or np.ndarray (2d)
      Data which will be used to calculate the explanations. It shouldn't contain
      the target column (See `y`).
      NOTE: If target variable is present in the data, some of the functionalities may
      not work properly.
  y : pd.Series or pd.DataFrame or np.ndarray (1d)
      Target variable with outputs / scores. It shall have the same length as `data`.
  predict_function : function, optional
      Function that takes two parameters (model, data) and returns a np.ndarray (1d)
      with model predictions (default is predict method extracted from the model).
      NOTE: This function needs to work with `data` as pd.DataFrame.
  residual_function : function, optional
      Function that takes three parameters (model, data, y) and returns a np.ndarray (1d)
      with model residuals (default is a function constructed from `predict_function`).
  weights : pd.Series or np.ndarray (1d), optional
      Sampling weights for observations in `data`. It shall have the same length as
      `data` (default is `None`).
  label : str, optional
      Model name to appear in result and plots
      (default is last element of the class attribute extracted from the model).
  model_class : str, optional
      Class of the model that is used e.g. to choose the `predict_function`
      (default is the class attribute extracted from the model).
      NOTE: Use if your model is wrapped with Pipeline.
  verbose : bool
      Print diagnostic messages during the Explainer initialization (default is `True`).
  precalculate : bool
      Calculate y_hat (predicted values) and residuals during the Explainer
      initialization (default is `True`).
  model_type : {'regression', 'classification', None}
      Model task type that is used e.g. in `model_performance()` and `model_parts()`
      (default is try to extract the information from the model, else `None`).
  model_info: dict, optional
      Dict `{'model_package', 'model_package_version', ...}` containing additional
      information to be stored.
  
  Attributes
  --------
  model : object
      A model to be explained.
  data : pd.DataFrame
      Data which will be used to calculate the explanations.
  y : np.ndarray (1d)
      Target variable with outputs / scores.
  predict_function : function
      Function that takes two arguments (model, data) and returns np.ndarray (1d)
      with model predictions.
  y_hat : np.ndarray (1d)
      Model predictions for `data`.
  residual_function : function
      Function that takes three arguments (model, data, y) and returns np.ndarray (1d)
      with model residuals.
  residuals : np.ndarray (1d)
      Model residuals for `data`.
  weights : np.ndarray (1d)
      Sampling weights for observations in `data`.
  label : str
      Name to appear in result and plots.
  model_class : str
      Class of the model.
  model_type : {'regression', 'classification', `None`}
      Model task type.
  model_info: dict
      Dict `{'model_package', 'model_package_version', ...}` containing additional
      information.
  
  Notes
  --------
  - https://pbiecek.github.io/ema/dataSetsIntro.html#ExplainersTitanicPythonCode
class_docstr_tok: ["Create","Model","Explainer","Black-box","models","may","have","very","different","structures",".","This","class","creates","a","unified","representation","of","a","model",",","which","can","be","further","processed","by","various","explanations",".","Methods","of","this","class","produce","explanation","objects",",","that","contain","the","main","result","attribute",",","and","can","be","visualised","using","the","plot","method",".","The","`","model","`","is","the","only","required","parameter",",","but","most","of","the","explanations","require","that","other","parameters","are","provided","(","See","`","data","`",",","`","y","`",",","`","predict_function","`",",","`","model_type","`",")",".","Parameters","--","--","--","--","--","model",":","object","Model","to","be","explained",".","data",":","pd.DataFrame","or","np.ndarray","(","2d",")","Data","which","will","be","used","to","calculate","the","explanations",".","It","should","n't","contain","the","target","column","(","See","`","y","`",")",".","NOTE",":","If","target","variable","is","present","in","the","data",",","some","of","the","functionalities","may","not","work","properly",".","y",":","pd.Series","or","pd.DataFrame","or","np.ndarray","(","1d",")","Target","variable","with","outputs","\/","scores",".","It","shall","have","the","same","length","as","`","data","`",".","predict_function",":","function",",","optional","Function","that","takes","two","parameters","(","model",",","data",")","and","returns","a","np.ndarray","(","1d",")","with","model","predictions","(","default","is","predict","method","extracted","from","the","model",")",".","NOTE",":","This","function","needs","to","work","with","`","data","`","as","pd.DataFrame",".","residual_function",":","function",",","optional","Function","that","takes","three","parameters","(","model",",","data",",","y",")","and","returns","a","np.ndarray","(","1d",")","with","model","residuals","(","default","is","a","function","constructed","from","`","predict_function","`",")",".","weights",":","pd.Series","or","np.ndarray","(","1d",")",",","optional","Sampling","weights","for","observations","in","`","data","`",".","It","shall","have","the","same","length","as","`","data","`","(","default","is","`","None","`",")",".","label",":","str",",","optional","Model","name","to","appear","in","result","and","plots","(","default","is","last","element","of","the","class","attribute","extracted","from","the","model",")",".","model_class",":","str",",","optional","Class","of","the","model","that","is","used","e.g",".","to","choose","the","`","predict_function","`","(","default","is","the","class","attribute","extracted","from","the","model",")",".","NOTE",":","Use","if","your","model","is","wrapped","with","Pipeline",".","verbose",":","bool","Print","diagnostic","messages","during","the","Explainer","initialization","(","default","is","`","True","`",")",".","precalculate",":","bool","Calculate","y_hat","(","predicted","values",")","and","residuals","during","the","Explainer","initialization","(","default","is","`","True","`",")",".","model_type",":","{","'regression","'",",","'classification","'",",","None","}","Model","task","type","that","is","used","e.g",".","in","`","model_performance","(",")","`","and","`","model_parts","(",")","`","(","default","is","try","to","extract","the","information","from","the","model",",","else","`","None","`",")",".","model_info",":","dict",",","optional","Dict","`","{","'model_package","'",",","'model_package_version","'",",","...","}","`","containing","additional","information","to","be","stored",".","Attributes","--","--","--","--","model",":","object","A","model","to","be","explained",".","data",":","pd.DataFrame","Data","which","will","be","used","to","calculate","the","explanations",".","y",":","np.ndarray","(","1d",")","Target","variable","with","outputs","\/","scores",".","predict_function",":","function","Function","that","takes","two","arguments","(","model",",","data",")","and","returns","np.ndarray","(","1d",")","with","model","predictions",".","y_hat",":","np.ndarray","(","1d",")","Model","predictions","for","`","data","`",".","residual_function",":","function","Function","that","takes","three","arguments","(","model",",","data",",","y",")","and","returns","np.ndarray","(","1d",")","with","model","residuals",".","residuals",":","np.ndarray","(","1d",")","Model","residuals","for","`","data","`",".","weights",":","np.ndarray","(","1d",")","Sampling","weights","for","observations","in","`","data","`",".","label",":","str","Name","to","appear","in","result","and","plots",".","model_class",":","str","Class","of","the","model",".","model_type",":","{","'regression","'",",","'classification","'",",","`","None","`","}","Model","task","type",".","model_info",":","dict","Dict","`","{","'model_package","'",",","'model_package_version","'",",","...","}","`","containing","additional","information",".","Notes","--","--","--","--","-","https",":","\/\/pbiecek.github.io\/ema\/dataSetsIntro.html","#","ExplainersTitanicPythonCode"]
docstr: Calculate predict-level variable attributions as Break Down, Shapley Values or Shap Values
  
  Parameters
  -----------
  new_observation : pd.Series or np.ndarray (1d) or pd.DataFrame (1,p)
      An observation for which a prediction needs to be explained.
  type : {'break_down_interactions', 'break_down', 'shap', 'shap_wrapper'}
      Type of variable attributions (default is `'break_down_interactions'`).
  order : list of int or str, optional
      Parameter specific for `break_down_interactions` and `break_down`. Use a fixed
      order of variables for attribution calculation. Use integer values  or string
      variable names (default is `None`, which means order by importance).
  interaction_preference : int, optional
      Parameter specific for `break_down_interactions` type. Specify which interactions
      will be present in an explanation. The larger the integer, the more frequently
      interactions will be presented (default is `1`).
  path : list of int, optional
      Parameter specific for `shap`. If specified, then attributions for this path
      will be plotted (default is `'average'`, which plots attribution means for
      `B` random paths).
  N : int, optional
      Number of observations that will be sampled from the `data` attribute before
      the calculation of variable attributions. Default is `None` which means all `data`.
  B : int, optional
      Parameter specific for `shap`. Number of random paths to calculate
      variable attributions (default is `25`).
  keep_distributions :  bool, optional
      Save the distribution of partial predictions (default is `False`).
  label : str, optional
      Name to appear in result and plots. Overrides default.
  processes : int, optional
      Parameter specific for `shap`. Number of parallel processes to use in calculations.
      Iterated over `B` (default is `1`, which means no parallel computation).
  random_state : int, optional
      Set seed for random number generator (default is random seed).
  kwargs : dict
      Used only for `'shap_wrapper'`. Pass `shap_explainer_type` to specify, which
      Explainer shall be used: `{'TreeExplainer', 'DeepExplainer', 'GradientExplainer',
      'LinearExplainer', 'KernelExplainer'}` (default is `None`, which automatically
      chooses an Explainer to use).
      Also keyword arguments passed to one of the: `shap.TreeExplainer.shap_values,
      shap.DeepExplainer.shap_values, shap.GradientExplainer.shap_values,
      shap.LinearExplainer.shap_values, shap.KernelExplainer.shap_values`.
      See https://github.com/slundberg/shap
  
  Returns
  -----------
  BreakDown, Shap or ShapWrapper class object
      Explanation object containing the main result attribute and the plot method.
      Object class, its attributes, and the plot method depend on the `type` parameter.
  
  Notes
  --------
  - https://pbiecek.github.io/ema/breakDown.html
  - https://pbiecek.github.io/ema/iBreakDown.html
  - https://pbiecek.github.io/ema/shapley.html
  - https://github.com/slundberg/shap
docstr_tok: ["Calculate","predict-level","variable","attributions","as","Break","Down",",","Shapley","Values","or","Shap","Values","Parameters","--","--","--","--","--","-","new_observation",":","pd.Series","or","np.ndarray","(","1d",")","or","pd.DataFrame","(","1",",","p",")","An","observation","for","which","a","prediction","needs","to","be","explained",".","type",":","{","'break_down_interactions","'",",","'break_down","'",",","'shap","'",",","'shap_wrapper","'","}","Type","of","variable","attributions","(","default","is","`","'break_down_interactions","'","`",")",".","order",":","list","of","int","or","str",",","optional","Parameter","specific","for","`","break_down_interactions","`","and","`","break_down","`",".","Use","a","fixed","order","of","variables","for","attribution","calculation",".","Use","integer","values","or","string","variable","names","(","default","is","`","None","`",",","which","means","order","by","importance",")",".","interaction_preference",":","int",",","optional","Parameter","specific","for","`","break_down_interactions","`","type",".","Specify","which","interactions","will","be","present","in","an","explanation",".","The","larger","the","integer",",","the","more","frequently","interactions","will","be","presented","(","default","is","`","1","`",")",".","path",":","list","of","int",",","optional","Parameter","specific","for","`","shap","`",".","If","specified",",","then","attributions","for","this","path","will","be","plotted","(","default","is","`","'average","'","`",",","which","plots","attribution","means","for","`","B","`","random","paths",")",".","N",":","int",",","optional","Number","of","observations","that","will","be","sampled","from","the","`","data","`","attribute","before","the","calculation","of","variable","attributions",".","Default","is","`","None","`","which","means","all","`","data","`",".","B",":","int",",","optional","Parameter","specific","for","`","shap","`",".","Number","of","random","paths","to","calculate","variable","attributions","(","default","is","`","25","`",")",".","keep_distributions",":","bool",",","optional","Save","the","distribution","of","partial","predictions","(","default","is","`","False","`",")",".","label",":","str",",","optional","Name","to","appear","in","result","and","plots",".","Overrides","default",".","processes",":","int",",","optional","Parameter","specific","for","`","shap","`",".","Number","of","parallel","processes","to","use","in","calculations",".","Iterated","over","`","B","`","(","default","is","`","1","`",",","which","means","no","parallel","computation",")",".","random_state",":","int",",","optional","Set","seed","for","random","number","generator","(","default","is","random","seed",")",".","kwargs",":","dict","Used","only","for","`","'shap_wrapper","'","`",".","Pass","`","shap_explainer_type","`","to","specify",",","which","Explainer","shall","be","used",":","`","{","'TreeExplainer","'",",","'DeepExplainer","'",",","'GradientExplainer","'",",","'LinearExplainer","'",",","'KernelExplainer","'","}","`","(","default","is","`","None","`",",","which","automatically","chooses","an","Explainer","to","use",")",".","Also","keyword","arguments","passed","to","one","of","the",":","`","shap.TreeExplainer.shap_values",",","shap.DeepExplainer.shap_values",",","shap.GradientExplainer.shap_values",",","shap.LinearExplainer.shap_values",",","shap.KernelExplainer.shap_values","`",".","See","https",":","\/\/github.com\/slundberg\/shap","Returns","--","--","--","--","--","-","BreakDown",",","Shap","or","ShapWrapper","class","object","Explanation","object","containing","the","main","result","attribute","and","the","plot","method",".","Object","class",",","its","attributes",",","and","the","plot","method","depend","on","the","`","type","`","parameter",".","Notes","--","--","--","--","-","https",":","\/\/pbiecek.github.io\/ema\/breakDown.html","-","https",":","\/\/pbiecek.github.io\/ema\/iBreakDown.html","-","https",":","\/\/pbiecek.github.io\/ema\/shapley.html","-","https",":","\/\/github.com\/slundberg\/shap"]
code: def predict_parts(
      self,
      new_observation,
      type=(
          "break_down_interactions",
          "break_down",
          "shap",
          "shap_wrapper",
      ),
      order=None,
      interaction_preference=1,
      path="average",
      N=None,
      B=25,
      keep_distributions=False,
      label=None,
      processes=1,
      random_state=None,
      **kwargs,
  ):
      """Calculate predict-level variable attributions as Break Down, Shapley Values or Shap Values
  
      Parameters
      -----------
      new_observation : pd.Series or np.ndarray (1d) or pd.DataFrame (1,p)
          An observation for which a prediction needs to be explained.
      type : {'break_down_interactions', 'break_down', 'shap', 'shap_wrapper'}
          Type of variable attributions (default is `'break_down_interactions'`).
      order : list of int or str, optional
          Parameter specific for `break_down_interactions` and `break_down`. Use a fixed
          order of variables for attribution calculation. Use integer values  or string
          variable names (default is `None`, which means order by importance).
      interaction_preference : int, optional
          Parameter specific for `break_down_interactions` type. Specify which interactions
          will be present in an explanation. The larger the integer, the more frequently
          interactions will be presented (default is `1`).
      path : list of int, optional
          Parameter specific for `shap`. If specified, then attributions for this path
          will be plotted (default is `'average'`, which plots attribution means for
          `B` random paths).
      N : int, optional
          Number of observations that will be sampled from the `data` attribute before
          the calculation of variable attributions. Default is `None` which means all `data`.
      B : int, optional
          Parameter specific for `shap`. Number of random paths to calculate
          variable attributions (default is `25`).
      keep_distributions :  bool, optional
          Save the distribution of partial predictions (default is `False`).
      label : str, optional
          Name to appear in result and plots. Overrides default.
      processes : int, optional
          Parameter specific for `shap`. Number of parallel processes to use in calculations.
          Iterated over `B` (default is `1`, which means no parallel computation).
      random_state : int, optional
          Set seed for random number generator (default is random seed).
      kwargs : dict
          Used only for `'shap_wrapper'`. Pass `shap_explainer_type` to specify, which
          Explainer shall be used: `{'TreeExplainer', 'DeepExplainer', 'GradientExplainer',
          'LinearExplainer', 'KernelExplainer'}` (default is `None`, which automatically
          chooses an Explainer to use).
          Also keyword arguments passed to one of the: `shap.TreeExplainer.shap_values,
          shap.DeepExplainer.shap_values, shap.GradientExplainer.shap_values,
          shap.LinearExplainer.shap_values, shap.KernelExplainer.shap_values`.
          See https://github.com/slundberg/shap
  
      Returns
      -----------
      BreakDown, Shap or ShapWrapper class object
          Explanation object containing the main result attribute and the plot method.
          Object class, its attributes, and the plot method depend on the `type` parameter.
  
      Notes
      --------
      - https://pbiecek.github.io/ema/breakDown.html
      - https://pbiecek.github.io/ema/iBreakDown.html
      - https://pbiecek.github.io/ema/shapley.html
      - https://github.com/slundberg/shap
      """
  
      checks.check_data_again(self.data)
  
      types = (
          "break_down_interactions",
          "break_down",
          "shap",
          "shap_wrapper",
      )
      _type = checks.check_method_type(type, types)
  
      if isinstance(N, int):
          # temporarly overwrite data in the Explainer (fastest way)
          # at the end of predict_parts fix the Explainer (add original data)
          if isinstance(random_state, int):
              np.random.seed(random_state)
          N = min(N, self.data.shape[0])
          I = np.random.choice(
              np.arange(self.data.shape[0]), N, replace=False
          )
          from copy import deepcopy
  
          _data = deepcopy(self.data)
          self.data = self.data.iloc[I, :]
  
      if _type == "break_down_interactions" or _type == "break_down":
          _predict_parts = BreakDown(
              type=_type,
              keep_distributions=keep_distributions,
              order=order,
              interaction_preference=interaction_preference,
          )
      elif _type == "shap":
          _predict_parts = Shap(
              keep_distributions=keep_distributions,
              path=path,
              B=B,
              processes=processes,
              random_state=random_state,
          )
      elif _type == "shap_wrapper":
          _global_checks.global_check_import(
              "shap", "SHAP explanations"
          )
          _predict_parts = ShapWrapper("predict_parts")
      else:
          raise TypeError("Wrong type parameter.")
  
      _predict_parts.fit(self, new_observation, **kwargs)
  
      if label:
          _predict_parts.result["label"] = label
  
      if isinstance(N, int):
          self.data = _data
  
      return _predict_parts
  
imports: import numpy
  from dalex.model_explanations import ModelPerformance, VariableImportance, AggregatedProfiles, ResidualDiagnostics
  from dalex.predict_explanations import BreakDown, Shap, CeterisParibus
  from dalex.wrappers import ShapWrapper
  from dalex.fairness import GroupFairnessClassification, GroupFairnessRegression
  from .None import checks
  from .None import utils
  from .None import helper
  from ..None import _global_checks
label_desc: Use image node_id 4 for calling the Explainer obj's underlying member method code with example usage: obj.predict_parts(new_observation, type, order, interaction_preference, path, N, B, keep_distributions, label, processes, random_state) and returns: _predict_parts