code: def compute_feature_importance(self) -> pd.DataFrame:
      feature_importance_vals = defaultdict(list)
      for batch_idx, data in enumerate(self.data_loader):
          for r in range(self.repeat):
              pred_value = self.pred_fn(self.model, data)
              for feature_idx, feature_id in enumerate(
                  self.sorted_feature_ids
              ):
                  copy_data = copy.deepcopy(data)
                  perturbed_data = self.perturb_fn(
                      copy_data, feature_idx
                  )
                  perturbed_pred_value = self.pred_fn(
                      self.model, perturbed_data
                  )
                  feature_importance_vals[feature_id].append(
                      torch.mean(
                          torch.abs(perturbed_pred_value - pred_value)
                      ).detach()
                  )
              logger.info(f"Processed {batch_idx} batches {r}-th time")
  
      feature_importance_mean = {
          k: torch.mean(torch.stack(v)).item()
          for k, v in feature_importance_vals.items()
      }
      result_df = pd.DataFrame.from_dict(
          feature_importance_mean,
          orient="index",
          columns=["feature_importance"],
      ).sort_values(by=["feature_importance"], ascending=False)
      # Fblearner UI can't show row names (index). So manually add names as a column
      result_df.insert(0, "feature_id", result_df.index)
      return result_df
  
file_path: ReAgent/reagent/evaluation/feature_importance/feature_importance_perturbation.py
imports: import copy
  import logging
  from collections import defaultdict
  from typing import Any, Callable, Optional
  import pandas
  import torch
  import torch.nn
  from reagent.core.dataclasses import dataclass
  from reagent.evaluation.feature_importance.feature_importance_base import FeatureImportanceBase
label_desc: Use image node_id 1 for calling the FeatureImportancePerturbation obj's underlying member method code with example usage: obj.compute_feature_importance() and returns: result_df