code: def build_KD_tree(
      self,
      data_df_copy,
      desired_range,
      desired_class,
      predicted_outcome_name,
  ):
      # Stores the predictions on the training data
      dataset_instance = self.data_interface.prepare_query_instance(
          query_instance=data_df_copy[self.data_interface.feature_names]
      )
  
      predictions = self.get_model_output_from_scores(
          self.model.get_output(dataset_instance, model_score=True)
      ).flatten()
      # TODO: Is it okay to insert a column in the original dataframe with the predicted outcome? This is memory-efficient
      data_df_copy[predicted_outcome_name] = predictions
  
      # segmenting the dataset according to outcome
      dataset_with_predictions = None
      if self.model.model_type == ModelTypes.Classifier:
          dataset_with_predictions = data_df_copy.loc[
              [i == desired_class for i in predictions]
          ].copy()
  
      elif self.model.model_type == ModelTypes.Regressor:
          dataset_with_predictions = data_df_copy.loc[
              [
                  desired_range[0] <= pred <= desired_range[1]
                  for pred in predictions
              ]
          ].copy()
  
      KD_tree = None
      # Prepares the KD trees for DiCE
      if len(dataset_with_predictions) > 0:
          dummies = pd.get_dummies(
              dataset_with_predictions[
                  self.data_interface.feature_names
              ]
          )
          KD_tree = KDTree(dummies)
  
      return dataset_with_predictions, KD_tree, predictions
  
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 25 for calling the ExplainerBase obj's underlying member method code with example usage: obj.build_KD_tree(data_df_copy, desired_range, desired_class, predicted_outcome_name) and returns: dataset_with_predictions,  KD_tree,  predictions