docstr: Explain prediction made by classifier on instance `X`.
  
  Parameters
  ----------
  X
      Instance to be explained.
  threshold
      Minimum anchor precision threshold. The algorithm tries to find an anchor that maximizes the coverage
      under precision constraint. The precision constraint is formally defined as
      :math:`P(prec(A) \ge t) \ge 1 - \delta`, where :math:`A` is an anchor, :math:`t` is the `threshold`
      parameter, :math:`\delta` is the `delta` parameter, and :math:`prec(\cdot)` denotes the precision
      of an anchor. In other words, we are seeking for an anchor having its precision greater or equal than
      the given `threshold` with a confidence of `(1 - delta)`. A higher value guarantees that the anchors are
      faithful to the model, but also leads to more computation time. Note that there are cases in which the
      precision constraint cannot be satisfied due to the quantile-based discretisation of the numerical
      features. If that is the case, the best (i.e. highest coverage) non-eligible anchor is returned.
  delta
      Significance threshold. `1 - delta` represents the confidence threshold for the anchor precision
      (see `threshold`) and the selection of the best anchor candidate in each iteration (see `tau`).
  tau
      Multi-armed bandit parameter used to select candidate anchors in each iteration. The multi-armed bandit
      algorithm tries to find within a tolerance `tau` the most promising (i.e. according to the precision)
      `beam_size` candidate anchor(s) from a list of proposed anchors. Formally, when the `beam_size=1`,
      the multi-armed bandit algorithm seeks to find an anchor :math:`A` such that
      :math:`P(prec(A) \ge prec(A^\star) - \tau) \ge 1 - \delta`, where :math:`A^\star` is the anchor
      with the highest true precision (which we don't know), :math:`\tau` is the `tau` parameter,
      :math:`\delta` is the `delta` parameter, and :math:`prec(\cdot)` denotes the precision of an anchor.
      In other words, in each iteration, the algorithm returns with a probability of at least `1 - delta` an
      anchor :math:`A` with a precision within an error tolerance of `tau` from the precision of the
      highest true precision anchor :math:`A^\star`. A bigger value for `tau` means faster convergence but also
      looser anchor conditions.
  batch_size
      Batch size used for sampling. The Anchor algorithm will query the black-box model in batches of size
      `batch_size`. A larger `batch_size` gives more confidence in the anchor, again at the expense of
      computation time since it involves more model prediction calls.
  coverage_samples
      Number of samples used to estimate coverage from during result search.
  beam_size
      Number of candidate anchors selected by the multi-armed bandit algorithm in each iteration from a list of
      proposed anchors. A bigger beam  width can lead to a better overall anchor (i.e. prevents the algorithm
      of getting stuck in a local maximum) at the expense of more computation time.
  stop_on_first
      If ``True``, the beam search algorithm will return the first anchor that has satisfies the
      probability constraint.
  max_anchor_size
      Maximum number of features in result.
  min_samples_start
      Min number of initial samples.
  n_covered_ex
      How many examples where anchors apply to store for each anchor sampled during search
      (both examples where prediction on samples agrees/disagrees with `desired_label` are stored).
  binary_cache_size
      The result search pre-allocates `binary_cache_size` batches for storing the binary arrays
      returned during sampling.
  cache_margin
      When only ``max(cache_margin, batch_size)`` positions in the binary cache remain empty, a new cache
      of the same size is pre-allocated to continue buffering samples.
  verbose
      Display updates during the anchor search iterations.
  verbose_every
      Frequency of displayed iterations during anchor search process.
  
  Returns
  -------
  explanation
      `Explanation` object containing the result explaining the instance with additional metadata as attributes.
      See usage at `AnchorTabular examples`_ for details.
  
      .. _AnchorTabular examples:
          https://docs.seldon.io/projects/alibi/en/stable/methods/Anchors.html
  
  Raises
  ------
  :py:class:`alibi.exceptions.NotFittedError`
      If `fit` has not been called prior to calling `explain`.
code: def explain(
      self,
      X: np.ndarray,
      threshold: float = 0.95,
      delta: float = 0.1,
      tau: float = 0.15,
      batch_size: int = 100,
      coverage_samples: int = 10000,
      beam_size: int = 1,
      stop_on_first: bool = False,
      max_anchor_size: Optional[int] = None,
      min_samples_start: int = 100,
      n_covered_ex: int = 10,
      binary_cache_size: int = 10000,
      cache_margin: int = 1000,
      verbose: bool = False,
      verbose_every: int = 1,
      **kwargs: Any,
  ) -> Explanation:
      """
      Explain prediction made by classifier on instance `X`.
  
      Parameters
      ----------
      X
          Instance to be explained.
      threshold
          Minimum anchor precision threshold. The algorithm tries to find an anchor that maximizes the coverage
          under precision constraint. The precision constraint is formally defined as
          :math:`P(prec(A) \\ge t) \\ge 1 - \\delta`, where :math:`A` is an anchor, :math:`t` is the `threshold`
          parameter, :math:`\\delta` is the `delta` parameter, and :math:`prec(\\cdot)` denotes the precision
          of an anchor. In other words, we are seeking for an anchor having its precision greater or equal than
          the given `threshold` with a confidence of `(1 - delta)`. A higher value guarantees that the anchors are
          faithful to the model, but also leads to more computation time. Note that there are cases in which the
          precision constraint cannot be satisfied due to the quantile-based discretisation of the numerical
          features. If that is the case, the best (i.e. highest coverage) non-eligible anchor is returned.
      delta
          Significance threshold. `1 - delta` represents the confidence threshold for the anchor precision
          (see `threshold`) and the selection of the best anchor candidate in each iteration (see `tau`).
      tau
          Multi-armed bandit parameter used to select candidate anchors in each iteration. The multi-armed bandit
          algorithm tries to find within a tolerance `tau` the most promising (i.e. according to the precision)
          `beam_size` candidate anchor(s) from a list of proposed anchors. Formally, when the `beam_size=1`,
          the multi-armed bandit algorithm seeks to find an anchor :math:`A` such that
          :math:`P(prec(A) \\ge prec(A^\\star) - \\tau) \\ge 1 - \\delta`, where :math:`A^\\star` is the anchor
          with the highest true precision (which we don't know), :math:`\\tau` is the `tau` parameter,
          :math:`\\delta` is the `delta` parameter, and :math:`prec(\\cdot)` denotes the precision of an anchor.
          In other words, in each iteration, the algorithm returns with a probability of at least `1 - delta` an
          anchor :math:`A` with a precision within an error tolerance of `tau` from the precision of the
          highest true precision anchor :math:`A^\\star`. A bigger value for `tau` means faster convergence but also
          looser anchor conditions.
      batch_size
          Batch size used for sampling. The Anchor algorithm will query the black-box model in batches of size
          `batch_size`. A larger `batch_size` gives more confidence in the anchor, again at the expense of
          computation time since it involves more model prediction calls.
      coverage_samples
          Number of samples used to estimate coverage from during result search.
      beam_size
          Number of candidate anchors selected by the multi-armed bandit algorithm in each iteration from a list of
          proposed anchors. A bigger beam  width can lead to a better overall anchor (i.e. prevents the algorithm
          of getting stuck in a local maximum) at the expense of more computation time.
      stop_on_first
          If ``True``, the beam search algorithm will return the first anchor that has satisfies the
          probability constraint.
      max_anchor_size
          Maximum number of features in result.
      min_samples_start
          Min number of initial samples.
      n_covered_ex
          How many examples where anchors apply to store for each anchor sampled during search
          (both examples where prediction on samples agrees/disagrees with `desired_label` are stored).
      binary_cache_size
          The result search pre-allocates `binary_cache_size` batches for storing the binary arrays
          returned during sampling.
      cache_margin
          When only ``max(cache_margin, batch_size)`` positions in the binary cache remain empty, a new cache
          of the same size is pre-allocated to continue buffering samples.
      verbose
          Display updates during the anchor search iterations.
      verbose_every
          Frequency of displayed iterations during anchor search process.
  
      Returns
      -------
      explanation
          `Explanation` object containing the result explaining the instance with additional metadata as attributes.
          See usage at `AnchorTabular examples`_ for details.
  
          .. _AnchorTabular examples:
              https://docs.seldon.io/projects/alibi/en/stable/methods/Anchors.html
  
      Raises
      ------
      :py:class:`alibi.exceptions.NotFittedError`
          If `fit` has not been called prior to calling `explain`.
      """
      if not self._fitted:
          raise NotFittedError(self.meta["name"])
  
      # transform one-hot encodings to labels if ohe == True
      X = (
          ohe_to_ord(
              X_ohe=X.reshape(1, -1), cat_vars_ohe=self.cat_vars_ohe
          )[0].reshape(-1)
          if self.ohe
          else X
      )
  
      # get params for storage in meta
      params = locals()
      remove = ["X", "self"]
      for key in remove:
          params.pop(key)
  
      for sampler in self.samplers:
          sampler.set_instance_label(X)
          sampler.set_n_covered(n_covered_ex)
      self.instance_label = self.samplers[0].instance_label
  
      # build feature encoding and mappings from the instance values to database rows where
      # similar records are found get anchors and add metadata
      self._build_sampling_lookups(X)
  
      # get anchors
      mab = AnchorBaseBeam(
          samplers=self.samplers,
          sample_cache_size=binary_cache_size,
          cache_margin=cache_margin,
          **kwargs,
      )
      result: Any = mab.anchor_beam(
          delta=delta,
          epsilon=tau,
          desired_confidence=threshold,
          beam_size=beam_size,
          min_samples_start=min_samples_start,
          max_anchor_size=max_anchor_size,
          batch_size=batch_size,
          coverage_samples=coverage_samples,
          verbose=verbose,
          verbose_every=verbose_every,
      )
      self.mab = mab
  
      return self._build_explanation(
          X, result, self.instance_label, params
      )
  
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 4 for calling the AnchorTabular obj's underlying member method code with example usage: obj.explain(X, threshold, delta, tau, batch_size, coverage_samples, beam_size, stop_on_first, max_anchor_size, min_samples_start, n_covered_ex, binary_cache_size, cache_margin, verbose, verbose_every) and returns: self