docstr: Estimate feature importance scores for the given inputs.
  
  :param query_instances: A list of inputs for which to compute the
                          feature importances. These can be provided as a dataframe.
  :param cf_examples_list: If precomputed, a list of counterfactual
                           examples for every input point. If cf_examples_list is provided, then
                           all the following parameters are ignored.
  :param total_CFs: The number of counterfactuals to generate per input
                    (default is 10)
  :param other_parameters: These are the same as the generate_counterfactuals method.
  
  :returns: An object of class CounterfactualExplanations that includes
            the list of counterfactuals per input, local feature importances per
            input, and the global feature importance summarized over all inputs.
code: def feature_importance(
      self,
      query_instances,
      cf_examples_list=None,
      total_CFs=10,
      local_importance=True,
      global_importance=True,
      desired_class="opposite",
      desired_range=None,
      permitted_range=None,
      features_to_vary="all",
      stopping_threshold=0.5,
      posthoc_sparsity_param=0.1,
      posthoc_sparsity_algorithm="linear",
      **kwargs,
  ):
      """Estimate feature importance scores for the given inputs.
  
      :param query_instances: A list of inputs for which to compute the
                              feature importances. These can be provided as a dataframe.
      :param cf_examples_list: If precomputed, a list of counterfactual
                               examples for every input point. If cf_examples_list is provided, then
                               all the following parameters are ignored.
      :param total_CFs: The number of counterfactuals to generate per input
                        (default is 10)
      :param other_parameters: These are the same as the generate_counterfactuals method.
  
      :returns: An object of class CounterfactualExplanations that includes
                the list of counterfactuals per input, local feature importances per
                input, and the global feature importance summarized over all inputs.
      """
      self._validate_counterfactual_configuration(
          query_instances=query_instances,
          total_CFs=total_CFs,
          desired_class=desired_class,
          desired_range=desired_range,
          permitted_range=permitted_range,
          features_to_vary=features_to_vary,
          stopping_threshold=stopping_threshold,
          posthoc_sparsity_param=posthoc_sparsity_param,
          posthoc_sparsity_algorithm=posthoc_sparsity_algorithm,
          kwargs=kwargs,
      )
      if cf_examples_list is None:
          cf_examples_list = self.generate_counterfactuals(
              query_instances,
              total_CFs,
              desired_class=desired_class,
              desired_range=desired_range,
              permitted_range=permitted_range,
              features_to_vary=features_to_vary,
              stopping_threshold=stopping_threshold,
              posthoc_sparsity_param=posthoc_sparsity_param,
              posthoc_sparsity_algorithm=posthoc_sparsity_algorithm,
              **kwargs,
          ).cf_examples_list
      allcols = (
          self.data_interface.categorical_feature_names
          + self.data_interface.continuous_feature_names
      )
      summary_importance = None
      local_importances = None
      if global_importance:
          summary_importance = {}
          # Initializing importance vector
          for col in allcols:
              summary_importance[col] = 0
  
      if local_importance:
          local_importances = [{} for _ in range(len(cf_examples_list))]
          # Initializing local importance for the ith query instance
          for i in range(len(cf_examples_list)):
              for col in allcols:
                  local_importances[i][col] = 0
  
      overall_num_cfs = 0
      # Summarizing the found counterfactuals
      for i in range(len(cf_examples_list)):
          cf_examples = cf_examples_list[i]
          org_instance = cf_examples.test_instance_df
  
          if cf_examples.final_cfs_df_sparse is not None:
              df = cf_examples.final_cfs_df_sparse
          else:
              df = cf_examples.final_cfs_df
  
          if df is None:
              continue
  
          per_query_point_cfs = 0
          for _, row in df.iterrows():
              per_query_point_cfs += 1
              for col in self.data_interface.continuous_feature_names:
                  if not np.isclose(org_instance[col].iat[0], row[col]):
                      if summary_importance is not None:
                          summary_importance[col] += 1
                      if local_importances is not None:
                          local_importances[i][col] += 1
              for col in self.data_interface.categorical_feature_names:
                  if org_instance[col].iat[0] != row[col]:
                      if summary_importance is not None:
                          summary_importance[col] += 1
                      if local_importances is not None:
                          local_importances[i][col] += 1
  
          if local_importances is not None:
              for col in allcols:
                  if per_query_point_cfs > 0:
                      local_importances[i][col] /= per_query_point_cfs
  
          overall_num_cfs += per_query_point_cfs
  
      if summary_importance is not None:
          for col in allcols:
              if overall_num_cfs > 0:
                  summary_importance[col] /= overall_num_cfs
  
      return CounterfactualExplanations(
          cf_examples_list,
          local_importance=local_importances,
          summary_importance=summary_importance,
      )
  
imports: import pickle
  from abc import ABC, abstractmethod
  from collections.abc import Iterable
  from typing import Any, List
  import numpy
  import pandas
  from raiutils.exceptions import UserConfigValidationException
  from sklearn.neighbors import KDTree
  from tqdm import tqdm
  from dice_ml.constants import ModelTypes, _PostHocSparsityTypes
  from dice_ml.counterfactual_explanations import CounterfactualExplanations
label_desc: Use image node_id 10 for calling the ExplainerBase obj's underlying member method code with example usage: obj.feature_importance(query_instances, cf_examples_list, total_CFs, local_importance, global_importance, desired_class, desired_range, permitted_range, features_to_vary, stopping_threshold, posthoc_sparsity_param, posthoc_sparsity_algorithm) and returns: CounterfactualExplanations