docstr: Check if a cf belongs to the target class or target range.
          
code: def is_cf_valid(self, model_score):
      """Check if a cf belongs to the target class or target range."""
      # Converting to single prediction if the prediction is provided as a
      # singleton array
      correct_dim = (
          1 if self.model.model_type == ModelTypes.Classifier else 0
      )
      if (
          hasattr(model_score, "shape")
          and len(model_score.shape) > correct_dim
      ):
          model_score = model_score[0]
      # Converting target_cf_class to a scalar (tf/torch have it as (1,1) shape)
      if self.model.model_type == ModelTypes.Classifier:
          target_cf_class = self.target_cf_class
          if hasattr(self.target_cf_class, "shape"):
              if len(self.target_cf_class.shape) == 1:
                  target_cf_class = self.target_cf_class[0]
              elif len(self.target_cf_class.shape) == 2:
                  target_cf_class = self.target_cf_class[0][0]
          target_cf_class = int(target_cf_class)
  
          if len(model_score) == 1:  # for tensorflow/pytorch models
              pred_1 = model_score[0]
              validity = (
                  True
                  if (
                      (
                          target_cf_class == 0
                          and pred_1 <= self.stopping_threshold
                      )
                      or (
                          target_cf_class == 1
                          and pred_1 >= self.stopping_threshold
                      )
                  )
                  else False
              )
              return validity
          elif len(model_score) == 2:  # binary
              pred_1 = model_score[1]
              validity = (
                  True
                  if (
                      (
                          target_cf_class == 0
                          and pred_1 <= self.stopping_threshold
                      )
                      or (
                          target_cf_class == 1
                          and pred_1 >= self.stopping_threshold
                      )
                  )
                  else False
              )
              return validity
          else:  # multiclass
              return np.argmax(model_score) == target_cf_class
      else:
          return (
              self.target_cf_range[0] <= model_score
              and model_score <= self.target_cf_range[1]
          )
  
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 20 for calling the ExplainerBase obj's underlying member method code with example usage: obj.is_cf_valid(model_score) and returns: unknown, validity, validity, unknown