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 model-level variable importance
  
  Parameters
  -----------
  loss_function : {'rmse', '1-auc', 'mse', 'mae', 'mad'} or function, optional
      If string, then such loss function will be used to assess variable importance
      (default is `'rmse'` or `'1-auc'`, depends on `model_type` attribute).
  type : {'variable_importance', 'ratio', 'difference', 'shap_wrapper'}
      Type of transformation that will be applied to dropout loss.
      (default is `'variable_importance'`, which is Permutational Variable Importance).
  N : int, optional
      Number of observations that will be sampled from the `data` attribute before
      the calculation of variable importance. `None` means all `data` (default is `1000`).
  B : int, optional
      Number of permutation rounds to perform on each variable (default is `10`).
  variables : array_like of str, optional
      Variables for which the importance will be calculated
      (default is `None`, which means all of the variables).
      NOTE: Ignored if `variable_groups` is not `None`.
  variable_groups : dict of lists, optional
      Group the variables to calculate their joint variable importance
      e.g. `{'X': ['x1', 'x2'], 'Y': ['y1', 'y2']}` (default is `None`).
  keep_raw_permutations: bool, optional
      Save results for all permutation rounds (default is `True`).
  label : str, optional
      Name to appear in result and plots. Overrides default.
  processes : int, optional
      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'}`.
      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
  -----------
  VariableImportance 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/featureImportance.html
  - https://github.com/slundberg/shap
docstr_tok: ["Calculate","model-level","variable","importance","Parameters","--","--","--","--","--","-","loss_function",":","{","'rmse","'",",","'","1-auc","'",",","'mse","'",",","'mae","'",",","'mad","'","}","or","function",",","optional","If","string",",","then","such","loss","function","will","be","used","to","assess","variable","importance","(","default","is","`","'rmse","'","`","or","`","'","1-auc","'","`",",","depends","on","`","model_type","`","attribute",")",".","type",":","{","'variable_importance","'",",","'ratio","'",",","'difference","'",",","'shap_wrapper","'","}","Type","of","transformation","that","will","be","applied","to","dropout","loss",".","(","default","is","`","'variable_importance","'","`",",","which","is","Permutational","Variable","Importance",")",".","N",":","int",",","optional","Number","of","observations","that","will","be","sampled","from","the","`","data","`","attribute","before","the","calculation","of","variable","importance",".","`","None","`","means","all","`","data","`","(","default","is","`","1000","`",")",".","B",":","int",",","optional","Number","of","permutation","rounds","to","perform","on","each","variable","(","default","is","`","10","`",")",".","variables",":","array_like","of","str",",","optional","Variables","for","which","the","importance","will","be","calculated","(","default","is","`","None","`",",","which","means","all","of","the","variables",")",".","NOTE",":","Ignored","if","`","variable_groups","`","is","not","`","None","`",".","variable_groups",":","dict","of","lists",",","optional","Group","the","variables","to","calculate","their","joint","variable","importance","e.g",".","`","{","'","X","'",":","[","'x1","'",",","'x2","'","]",",","'","Y","'",":","[","'y1","'",",","'y2","'","]","}","`","(","default","is","`","None","`",")",".","keep_raw_permutations",":","bool",",","optional","Save","results","for","all","permutation","rounds","(","default","is","`","True","`",")",".","label",":","str",",","optional","Name","to","appear","in","result","and","plots",".","Overrides","default",".","processes",":","int",",","optional","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","'","}","`",".","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","--","--","--","--","--","-","VariableImportance","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\/featureImportance.html","-","https",":","\/\/github.com\/slundberg\/shap"]
code: def model_parts(
      self,
      loss_function=None,
      type=(
          "variable_importance",
          "ratio",
          "difference",
          "shap_wrapper",
      ),
      N=1000,
      B=10,
      variables=None,
      variable_groups=None,
      keep_raw_permutations=True,
      label=None,
      processes=1,
      random_state=None,
      **kwargs,
  ):
      """Calculate model-level variable importance
  
      Parameters
      -----------
      loss_function : {'rmse', '1-auc', 'mse', 'mae', 'mad'} or function, optional
          If string, then such loss function will be used to assess variable importance
          (default is `'rmse'` or `'1-auc'`, depends on `model_type` attribute).
      type : {'variable_importance', 'ratio', 'difference', 'shap_wrapper'}
          Type of transformation that will be applied to dropout loss.
          (default is `'variable_importance'`, which is Permutational Variable Importance).
      N : int, optional
          Number of observations that will be sampled from the `data` attribute before
          the calculation of variable importance. `None` means all `data` (default is `1000`).
      B : int, optional
          Number of permutation rounds to perform on each variable (default is `10`).
      variables : array_like of str, optional
          Variables for which the importance will be calculated
          (default is `None`, which means all of the variables).
          NOTE: Ignored if `variable_groups` is not `None`.
      variable_groups : dict of lists, optional
          Group the variables to calculate their joint variable importance
          e.g. `{'X': ['x1', 'x2'], 'Y': ['y1', 'y2']}` (default is `None`).
      keep_raw_permutations: bool, optional
          Save results for all permutation rounds (default is `True`).
      label : str, optional
          Name to appear in result and plots. Overrides default.
      processes : int, optional
          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'}`.
          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
      -----------
      VariableImportance 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/featureImportance.html
      - https://github.com/slundberg/shap
      """
  
      checks.check_data_again(self.data)
  
      types = (
          "variable_importance",
          "ratio",
          "difference",
          "shap_wrapper",
      )
      aliases = {
          "permutational": "variable_importance",
          "feature_importance": "variable_importance",
      }
      _type = checks.check_method_type(type, types, aliases)
  
      loss_function = checks.check_method_loss_function(
          self, loss_function
      )
  
      if _type != "shap_wrapper":
          checks.check_y_again(self.y)
  
          _model_parts = VariableImportance(
              loss_function=loss_function,
              type=_type,
              N=N,
              B=B,
              variables=variables,
              variable_groups=variable_groups,
              processes=processes,
              random_state=random_state,
              keep_raw_permutations=keep_raw_permutations,
          )
          _model_parts.fit(self)
  
          if label:
              _model_parts.result["label"] = label
  
      elif _type == "shap_wrapper":
          _global_checks.global_check_import(
              "shap", "SHAP explanations"
          )
          _model_parts = ShapWrapper("model_parts")
          if isinstance(N, int):
              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
              )
              _new_observation = self.data.iloc[I, :]
          else:
              _new_observation = self.data
  
          _model_parts.fit(self, _new_observation, **kwargs)
      else:
          raise TypeError("Wrong type parameter")
  
      return _model_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 8 for calling the Explainer obj's underlying member method code with example usage: obj.model_parts(loss_function, type, N, B, variables, variable_groups, keep_raw_permutations, label, processes, random_state) and returns: _model_parts