code: def calculate_shap_predict_aspect_importance(
      explainer,
      new_observation,
      variable_groups,
      N,
      B,
      processes,
      random_state,
  ):
      r = np.random.RandomState(random_state)
      N = min(explainer.data.shape[0], N)
      ids = r.randint(0, explainer.data.shape[0], N)
      data_sample = explainer.data.iloc[ids, :].copy()
      p = len(variable_groups)
  
      if processes == 1:
          result_list = [
              iterate_paths(
                  explainer.predict,
                  data_sample,
                  new_observation,
                  variable_groups,
                  p,
                  b + 1,
                  np.random,
              )
              for b in range(B)
          ]
      else:
          # create number generator for each iteration
          ss = np.random.SeedSequence(random_state)
          generators = [np.random.default_rng(s) for s in ss.spawn(B)]
          pool = mp.get_context("spawn").Pool(processes)
          result_list = pool.starmap_async(
              iterate_paths,
              [
                  (
                      explainer.predict,
                      data_sample,
                      new_observation,
                      variable_groups,
                      p,
                      b + 1,
                      generators[b],
                  )
                  for b in range(B)
              ],
          ).get()
          pool.close()
  
      tmp_result = pd.concat(result_list)
  
      # average over all of the paths
      variable_average = tmp_result.pivot(
          index="aspect_name", columns="B", values="importance"
      ).mean(axis=1)
  
      # generate result pd.DataFrame
      result = pd.DataFrame(
          {
              "aspect_name": variable_average.index.tolist(),
              "importance": variable_average.values.tolist(),
              "label": explainer.label,
          }
      )
      result["variable_names"] = result["aspect_name"].map(
          variable_groups
      )
      variable_values = [
          new_observation[variables_list].values[0]
          for variables_list in result["variable_names"]
      ]
      result["variable_values"] = variable_values
      result = result.sort_values(
          by="importance", key=abs, ascending=False
      ).reset_index(drop=True)
      return result[
          [
              "aspect_name",
              "variable_names",
              "variable_values",
              "importance",
              "label",
          ]
      ]
  
file_path: DALEX/python/dalex/dalex/aspect/_predict_aspect_importance/utils.py
imports: import numpy
  import pandas
  from copy import deepcopy
  import multiprocessing
  from dalex import _global_checks
label_desc: Use image node_id 2 for calling a global function with example usage: calculate_shap_predict_aspect_importance(explainer, new_observation, variable_groups, N, B, processes, random_state) and returns: result