code: def calculate_predict_aspect_importance(
      explainer,
      new_observation,
      variable_groups,
      N,
      n_aspects,
      sample_method,
      f,
      random_state,
  ):
      _global_checks.global_check_import(
          "scikit-learn", "Predict Aspect Importance explanations"
      )
      # create sample from data and copy
      r = np.random.RandomState(random_state)
      N = min(explainer.data.shape[0], N)
      ids = r.randint(0, explainer.data.shape[0], N)
      n_sample = explainer.data.iloc[ids, :].copy()
      n_sample_changed = deepcopy(n_sample)
      n_sample_changed.reset_index(inplace=True, drop=True)
  
      if len(variable_groups) == 1:
          result = pd.DataFrame(
              {
                  "aspect_name": list(variable_groups.keys())[0],
                  "variable_names": [list(variable_groups.values())[0]],
                  "variable_values": new_observation[
                      list(variable_groups.values())[0]
                  ].values.tolist(),
                  "importance": explainer.predict(new_observation)
                  - explainer.y_hat.mean(),
                  "label": explainer.label,
              }
          )
          return result
  
      # generate binary matrix for replacing aspect
      X_prim = get_sample(
          N, len(variable_groups), sample_method, f, random_state
      )
  
      # replace aspect in sample with observation's values of features
      for i in range(n_sample_changed.shape[0]):
          for k, variables_set_key in enumerate(variable_groups):
              if X_prim[i, k] == 1:
                  variables = variable_groups[variables_set_key]
                  n_sample_changed.loc[i, variables] = [
                      new_observation.iloc[0][var] for var in variables
                  ]
  
      # calculate change in predictions
      y_changed = explainer.predict(
          n_sample_changed
      ) - explainer.predict(n_sample)
  
      # fit linear model to binary matrix and change in predictions vector to estimate aspect importance
      X_prim = pd.DataFrame(X_prim)
      X_prim.columns = [aspect_name for aspect_name in variable_groups]
  
      if n_aspects == None:
          from sklearn.linear_model import LinearRegression
  
          lr = LinearRegression()
          lr.fit(X_prim, y_changed)
          model_coef = lr.coef_
      else:
          from sklearn.linear_model import lasso_path
  
          lasso_res_matrix = lasso_path(X_prim, y_changed)[1]
          indx = np.max(
              np.where(
                  np.count_nonzero(lasso_res_matrix, axis=0)
                  <= n_aspects
              )
          )
          model_coef = lasso_res_matrix[:, indx]
  
      # generate result pd.DataFrame
      variable_names = [
          variable_groups[variables_set_key]
          for variables_set_key in variable_groups
      ]
      variable_values = [
          new_observation[variables_list].values[0]
          for variables_list in variable_names
      ]
      result = pd.DataFrame(
          {
              "aspect_name": X_prim.columns,
              "variable_names": variable_names,
              "variable_values": variable_values,
              "importance": model_coef,
              "label": explainer.label,
          }
      )
      result = result.sort_values(
          by="importance", key=abs, ascending=False
      ).reset_index(drop=True)
      return result
  
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 1 for calling a global function with example usage: calculate_predict_aspect_importance(explainer, new_observation, variable_groups, N, n_aspects, sample_method, f, random_state) and returns: result, result