class_docstr: A sampler that uses an underlying training set to draw records that have a subset of features with
  values specified in an instance to be explained, `X`. 
class_docstr_tok: ["A","sampler","that","uses","an","underlying","training","set","to","draw","records","that","have","a","subset","of","features","with","values","specified","in","an","instance","to","be","explained",",","`","X","`","."]
docstr: Obtain perturbed records by drawing samples from training data that contain the categorical labels and
  discretized numerical features and replacing the remainder of the record with arbitrary values.
  
  Parameters
  ----------
  anchor
      The integer represents the order of the result in a request array. The tuple contains
      encoded feature indices.
  num_samples
      Number of samples used when sampling from training set.
  compute_labels
      If ``True``, an array of comparisons between predictions on perturbed samples and instance to be
      explained is returned.
  
  Returns
  -------
  If ``compute_labels=True``, a list containing the following is returned
  
   - `covered_true` - perturbed examples where the anchor applies and the model prediction          on perturbation is the same as the instance prediction.
  
   - `covered_false` - perturbed examples where the anchor applies and the model prediction          is NOT the same as the instance prediction.
  
   - `labels` - `num_samples` ints indicating whether the prediction on the perturbed sample          matches (1) the label of the instance to be explained or not (0).
  
   - `data` -  Sampled data where ordinal features are binned (1 if in bin, 0 otherwise).
  
   - `coverage` - the coverage of the anchor.
  
   - `anchor[0]` - position of anchor in the batch request.
  
  Otherwise, a list containing the data matrix only is returned.
code: def __call__(
      self,
      anchor: Tuple[int, tuple],
      num_samples: int,
      compute_labels=True,
  ) -> Union[
      List[
          Union[
              np.ndarray, np.ndarray, np.ndarray, np.ndarray, float, int
          ]
      ],
      List[np.ndarray],
  ]:
      """
          Obtain perturbed records by drawing samples from training data that contain the categorical labels and
          discretized numerical features and replacing the remainder of the record with arbitrary values.
  
          Parameters
          ----------
          anchor
              The integer represents the order of the result in a request array. The tuple contains
              encoded feature indices.
          num_samples
              Number of samples used when sampling from training set.
          compute_labels
              If ``True``, an array of comparisons between predictions on perturbed samples and instance to be
              explained is returned.
  
          Returns
          -------
          If ``compute_labels=True``, a list containing the following is returned
  
           - `covered_true` - perturbed examples where the anchor applies and the model prediction \
           on perturbation is the same as the instance prediction.
  
           - `covered_false` - perturbed examples where the anchor applies and the model prediction \
           is NOT the same as the instance prediction.
  
           - `labels` - `num_samples` ints indicating whether the prediction on the perturbed sample \
           matches (1) the label of the instance to be explained or not (0).
  
           - `data` -  Sampled data where ordinal features are binned (1 if in bin, 0 otherwise).
  
           - `coverage` - the coverage of the anchor.
  
           - `anchor[0]` - position of anchor in the batch request.
  
          Otherwise, a list containing the data matrix only is returned.
          """
  
      raw_data, d_raw_data, coverage = self.perturbation(
          anchor[1], num_samples
      )
  
      # use the sampled, discretized raw data to construct a data matrix with the categorical ...
      # ... and binned ordinal data (1 if in bin, 0 otherwise)
      data = np.zeros((num_samples, len(self.enc2feat_idx)), int)
      for i in self.enc2feat_idx:
          if i in self.cat_lookup:
              data[:, i] = (
                  d_raw_data[:, self.enc2feat_idx[i]]
                  == self.cat_lookup[i]
              )
          else:
              d_records_sampled = d_raw_data[:, self.enc2feat_idx[i]]
              lower_bin, upper_bin = min(list(self.ord_lookup[i])), max(
                  list(self.ord_lookup[i])
              )
              idxs = np.where(
                  (lower_bin <= d_records_sampled)
                  & (d_records_sampled <= upper_bin)
              )
              data[idxs, i] = 1
  
      if compute_labels:
          labels = self.compare_labels(raw_data)
          covered_true = raw_data[labels, :][: self.n_covered_ex]
          covered_false = raw_data[np.logical_not(labels), :][
              : self.n_covered_ex
          ]
          return [
              covered_true,
              covered_false,
              labels.astype(int),
              data,
              coverage,
              anchor[0],
          ]  # type: ignore[return-value]
      else:
          return [data]
  
imports: import copy
  from collections import OrderedDict, defaultdict
  from itertools import accumulate
  from typing import Any, Callable, DefaultDict, Dict, List, Optional, Set, Tuple, Type, Union
  import numpy
  from alibi.api.defaults import DEFAULT_DATA_ANCHOR, DEFAULT_META_ANCHOR
  from alibi.api.interfaces import Explainer, Explanation, FitMixin
  from alibi.exceptions import NotFittedError, PredictorCallError, PredictorReturnTypeError
  from alibi.utils.discretizer import Discretizer
  from alibi.utils.mapping import ohe_to_ord, ord_to_ohe
  from alibi.utils.wrappers import ArgmaxTransformer
  from .anchor_base import AnchorBaseBeam
  from .anchor_explanation import AnchorExplanation
label_desc: Use image node_id 9 for calling the TabularSampler obj's underlying member method code with example usage: obj.__call__(anchor, num_samples, compute_labels) and returns: list, list