docstr: Estimate the feature importance of the policy.
  
  Given a batch of tabular observations, the importance of each feature is
  computed by perturbing each feature and computing the difference between the
  perturbed policy and the reference policy. The importance is computed for each
  feature and each perturbation is repeated `self.repeat` times.
  
  Args:
      batch: the batch of data to use for feature importance.
  
  Returns:
      A dict mapping each feature index string to its importance.
docstr_tok: ["Estimate","the","feature","importance","of","the","policy",".","Given","a","batch","of","tabular","observations",",","the","importance","of","each","feature","is","computed","by","perturbing","each","feature","and","computing","the","difference","between","the","perturbed","policy","and","the","reference","policy",".","The","importance","is","computed","for","each","feature","and","each","perturbation","is","repeated","`","self.repeat","`","times",".","Args",":","batch",":","the","batch","of","data","to","use","for","feature","importance",".","Returns",":","A","dict","mapping","each","feature","index","string","to","its","importance","."]
code: def estimate(self, batch: SampleBatchType) -> Dict[str, Any]:
      """Estimate the feature importance of the policy.
  
      Given a batch of tabular observations, the importance of each feature is
      computed by perturbing each feature and computing the difference between the
      perturbed policy and the reference policy. The importance is computed for each
      feature and each perturbation is repeated `self.repeat` times.
  
      Args:
          batch: the batch of data to use for feature importance.
  
      Returns:
          A dict mapping each feature index string to its importance.
      """
      batch = convert_ma_batch_to_sample_batch(batch)
      obs_batch = batch["obs"]
      n_features = obs_batch.shape[-1]
      importance = np.zeros((self.repeat, n_features))
  
      ref_actions, _, _ = self.policy.compute_actions(
          obs_batch, explore=False
      )
      for r in range(self.repeat):
          for i in range(n_features):
              copy_obs_batch = copy.deepcopy(obs_batch)
              _perturb_fn(copy_obs_batch, index=i)
              perturbed_actions, _, _ = self.policy.compute_actions(
                  copy_obs_batch, explore=False
              )
              importance[r, i] = np.mean(
                  np.abs(perturbed_actions - ref_actions)
              )
  
      # take an average across repeats
      importance = importance.mean(0)
      metrics = {
          f"feature_{i}": importance[i] for i in range(len(importance))
      }
  
      return metrics
  
file_path: ray/python/ray/rllib/offline/feature_importance.py
imports: import copy
  import numpy
  import pandas
  from typing import Callable, Dict, Any
  import ray
  from ray.data import Dataset
  from ray.rllib.policy import Policy
  from ray.rllib.policy.sample_batch import SampleBatch, convert_ma_batch_to_sample_batch
  from ray.rllib.utils.annotations import override, DeveloperAPI, ExperimentalAPI
  from ray.rllib.utils.typing import SampleBatchType
  from ray.rllib.offline.offline_evaluator import OfflineEvaluator
label_desc: Use image node_id 2 for calling the FeatureImportance obj's underlying member method code with example usage: obj.estimate(batch) and returns: metrics