docstr: Internal method for generating counterfactuals for a given query instance. Any explainerclass
     inherting from this class would need to implement this abstract method.
  
  :param query_instance: Input point for which counterfactuals are to be generated.
                         This can be a dataframe with one row.
  :param total_CFs: Total number of counterfactuals required.
  :param desired_class: Desired counterfactual class - can take 0 or 1. Default value
                        is "opposite" to the outcome class of query_instance for binary classification.
  :param desired_range: For regression problems. Contains the outcome range to
                        generate counterfactuals in.
  :param permitted_range: Dictionary with feature names as keys and permitted range in list as values.
                          Defaults to the range inferred from training data.
                          If None, uses the parameters initialized in data_interface.
  :param features_to_vary: Either a string "all" or a list of feature names to vary.
  :param stopping_threshold: Minimum threshold for counterfactuals target class probability.
  :param posthoc_sparsity_param: Parameter for the post-hoc operation on continuous features to enhance sparsity.
  :param posthoc_sparsity_algorithm: Perform either linear or binary search. Takes "linear" or "binary".
                                     Prefer binary search when a feature range is large (for instance,
                                     income varying from 10k to 1000k) and only if the features share a
                                     monotonic relationship with predicted outcome in the model.
  :param verbose: Whether to output detailed messages.
  :param sample_size: Sampling size
  :param random_seed: Random seed for reproducibility
  :param kwargs: Other parameters accepted by specific explanation method
  
  :returns: A CounterfactualExplanations object that contains the list of
            counterfactual examples per query_instance as one of its attributes.
code: def _generate_counterfactuals(
      self,
      query_instance,
      total_CFs,
      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",
      verbose=False,
      **kwargs,
  ):
      """Internal method for generating counterfactuals for a given query instance. Any explainerclass
         inherting from this class would need to implement this abstract method.
  
      :param query_instance: Input point for which counterfactuals are to be generated.
                             This can be a dataframe with one row.
      :param total_CFs: Total number of counterfactuals required.
      :param desired_class: Desired counterfactual class - can take 0 or 1. Default value
                            is "opposite" to the outcome class of query_instance for binary classification.
      :param desired_range: For regression problems. Contains the outcome range to
                            generate counterfactuals in.
      :param permitted_range: Dictionary with feature names as keys and permitted range in list as values.
                              Defaults to the range inferred from training data.
                              If None, uses the parameters initialized in data_interface.
      :param features_to_vary: Either a string "all" or a list of feature names to vary.
      :param stopping_threshold: Minimum threshold for counterfactuals target class probability.
      :param posthoc_sparsity_param: Parameter for the post-hoc operation on continuous features to enhance sparsity.
      :param posthoc_sparsity_algorithm: Perform either linear or binary search. Takes "linear" or "binary".
                                         Prefer binary search when a feature range is large (for instance,
                                         income varying from 10k to 1000k) and only if the features share a
                                         monotonic relationship with predicted outcome in the model.
      :param verbose: Whether to output detailed messages.
      :param sample_size: Sampling size
      :param random_seed: Random seed for reproducibility
      :param kwargs: Other parameters accepted by specific explanation method
  
      :returns: A CounterfactualExplanations object that contains the list of
                counterfactual examples per query_instance as one of its attributes.
      """
      pass
  
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 5 for calling the ExplainerBase obj's underlying member method code with example usage: obj._generate_counterfactuals(query_instance, total_CFs, desired_class, desired_range, permitted_range, features_to_vary, stopping_threshold, posthoc_sparsity_param, posthoc_sparsity_algorithm, verbose) without return types