docstr: Generic drift detector component which serves as a base class for methods using
  univariate tests. If n_features > 1, a multivariate correction is applied such that
  the false positive rate is upper bounded by the specified p-value, with equality in
  the case of independent features.
  
  Parameters
  ----------
  x_ref
      Data used as reference distribution.
  p_val
      p-value used for significance of the statistical test for each feature. If the FDR correction method
      is used, this corresponds to the acceptable q-value.
  x_ref_preprocessed
      Whether the given reference data `x_ref` has been preprocessed yet. If `x_ref_preprocessed=True`, only
      the test data `x` will be preprocessed at prediction time. If `x_ref_preprocessed=False`, the reference
      data will also be preprocessed.
  preprocess_at_init
      Whether to preprocess the reference data when the detector is instantiated. Otherwise, the reference
      data will be preprocessed at prediction time. Only applies if `x_ref_preprocessed=False`.
  update_x_ref
      Reference data can optionally be updated to the last n instances seen by the detector
      or via reservoir sampling with size n. For the former, the parameter equals {'last': n} while
      for reservoir sampling {'reservoir_sampling': n} is passed.
  preprocess_fn
      Function to preprocess the data before computing the data drift metrics.
      Typically a dimensionality reduction technique.
  correction
      Correction type for multivariate data. Either 'bonferroni' or 'fdr' (False Discovery Rate).
  n_features
      Number of features used in the statistical test. No need to pass it if no preprocessing takes place.
      In case of a preprocessing step, this can also be inferred automatically but could be more
      expensive to compute.
  input_shape
      Shape of input data. Needs to be provided for text data.
  data_type
      Optionally specify the data type (tabular, image or time-series). Added to metadata.
docstr_tok: ["Generic","drift","detector","component","which","serves","as","a","base","class","for","methods","using","univariate","tests",".","If","n_features",">","1",",","a","multivariate","correction","is","applied","such","that","the","false","positive","rate","is","upper","bounded","by","the","specified","p-value",",","with","equality","in","the","case","of","independent","features",".","Parameters","--","--","--","--","--","x_ref","Data","used","as","reference","distribution",".","p_val","p-value","used","for","significance","of","the","statistical","test","for","each","feature",".","If","the","FDR","correction","method","is","used",",","this","corresponds","to","the","acceptable","q-value",".","x_ref_preprocessed","Whether","the","given","reference","data","`","x_ref","`","has","been","preprocessed","yet",".","If","`","x_ref_preprocessed=True","`",",","only","the","test","data","`","x","`","will","be","preprocessed","at","prediction","time",".","If","`","x_ref_preprocessed=False","`",",","the","reference","data","will","also","be","preprocessed",".","preprocess_at_init","Whether","to","preprocess","the","reference","data","when","the","detector","is","instantiated",".","Otherwise",",","the","reference","data","will","be","preprocessed","at","prediction","time",".","Only","applies","if","`","x_ref_preprocessed=False","`",".","update_x_ref","Reference","data","can","optionally","be","updated","to","the","last","n","instances","seen","by","the","detector","or","via","reservoir","sampling","with","size","n.","For","the","former",",","the","parameter","equals","{","'last","'",":","n","}","while","for","reservoir","sampling","{","'reservoir_sampling","'",":","n","}","is","passed",".","preprocess_fn","Function","to","preprocess","the","data","before","computing","the","data","drift","metrics",".","Typically","a","dimensionality","reduction","technique",".","correction","Correction","type","for","multivariate","data",".","Either","'bonferroni","'","or","'fdr","'","(","False","Discovery","Rate",")",".","n_features","Number","of","features","used","in","the","statistical","test",".","No","need","to","pass","it","if","no","preprocessing","takes","place",".","In","case","of","a","preprocessing","step",",","this","can","also","be","inferred","automatically","but","could","be","more","expensive","to","compute",".","input_shape","Shape","of","input","data",".","Needs","to","be","provided","for","text","data",".","data_type","Optionally","specify","the","data","type","(","tabular",",","image","or","time-series",")",".","Added","to","metadata","."]
code: def __init__(
      self,
      x_ref: Union[np.ndarray, list],
      p_val: float = 0.05,
      x_ref_preprocessed: bool = False,
      preprocess_at_init: bool = True,
      update_x_ref: Optional[Dict[str, int]] = None,
      preprocess_fn: Optional[Callable] = None,
      correction: str = "bonferroni",
      n_features: Optional[int] = None,
      input_shape: Optional[tuple] = None,
      data_type: Optional[str] = None,
  ) -> None:
      """
      Generic drift detector component which serves as a base class for methods using
      univariate tests. If n_features > 1, a multivariate correction is applied such that
      the false positive rate is upper bounded by the specified p-value, with equality in
      the case of independent features.
  
      Parameters
      ----------
      x_ref
          Data used as reference distribution.
      p_val
          p-value used for significance of the statistical test for each feature. If the FDR correction method
          is used, this corresponds to the acceptable q-value.
      x_ref_preprocessed
          Whether the given reference data `x_ref` has been preprocessed yet. If `x_ref_preprocessed=True`, only
          the test data `x` will be preprocessed at prediction time. If `x_ref_preprocessed=False`, the reference
          data will also be preprocessed.
      preprocess_at_init
          Whether to preprocess the reference data when the detector is instantiated. Otherwise, the reference
          data will be preprocessed at prediction time. Only applies if `x_ref_preprocessed=False`.
      update_x_ref
          Reference data can optionally be updated to the last n instances seen by the detector
          or via reservoir sampling with size n. For the former, the parameter equals {'last': n} while
          for reservoir sampling {'reservoir_sampling': n} is passed.
      preprocess_fn
          Function to preprocess the data before computing the data drift metrics.
          Typically a dimensionality reduction technique.
      correction
          Correction type for multivariate data. Either 'bonferroni' or 'fdr' (False Discovery Rate).
      n_features
          Number of features used in the statistical test. No need to pass it if no preprocessing takes place.
          In case of a preprocessing step, this can also be inferred automatically but could be more
          expensive to compute.
      input_shape
          Shape of input data. Needs to be provided for text data.
      data_type
          Optionally specify the data type (tabular, image or time-series). Added to metadata.
      """
      super().__init__()
      if p_val is None:
          logger.warning(
              "No p-value set for the drift threshold. Need to set it to detect data drift."
          )
  
      # x_ref preprocessing
      self.preprocess_at_init = preprocess_at_init
      self.x_ref_preprocessed = x_ref_preprocessed
      if preprocess_fn is not None and not isinstance(preprocess_fn, Callable):  # type: ignore[arg-type]
          raise ValueError("`preprocess_fn` is not a valid Callable.")
      if (
          self.preprocess_at_init
          and not self.x_ref_preprocessed
          and preprocess_fn is not None
      ):
          self.x_ref = preprocess_fn(x_ref)
      else:
          self.x_ref = x_ref
  
      # Other attributes
      self.p_val = p_val
      self.update_x_ref = update_x_ref
      self.preprocess_fn = preprocess_fn
      self.correction = correction
      self.n = len(x_ref)
  
      # store input shape for save and load functionality
      self.input_shape = get_input_shape(input_shape, x_ref)
  
      # compute number of features for the univariate tests
      if isinstance(n_features, int):
          self.n_features = n_features
      elif (
          not isinstance(preprocess_fn, Callable)
          or preprocess_at_init
          or x_ref_preprocessed
      ):
          # infer features from preprocessed reference data
          self.n_features = self.x_ref.reshape(
              self.x_ref.shape[0], -1
          ).shape[-1]
      else:  # infer number of features after applying preprocessing step
          x = self.preprocess_fn(x_ref[0:1])
          self.n_features = x.reshape(x.shape[0], -1).shape[-1]
  
      if (
          correction not in ["bonferroni", "fdr"]
          and self.n_features > 1
      ):
          raise ValueError(
              "Only `bonferroni` and `fdr` are acceptable for multivariate correction."
          )
  
      # set metadata
      self.meta[
          "online"
      ] = False  # offline refers to fitting the CDF for K-S
      self.meta["data_type"] = data_type
      self.meta["detector_type"] = "drift"
  
imports: import logging
  from abc import abstractmethod
  from typing import Callable, Dict, List, Optional, Tuple, Union, Any
  import numpy
  from alibi_detect.base import BaseDetector, concept_drift_dict, DriftConfigMixin
  from alibi_detect.cd.utils import get_input_shape, update_reference
  from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow
  from alibi_detect.utils.statstest import fdr
  from scipy.stats import binom_test, ks_2samp
  from sklearn.model_selection import StratifiedKFold
label_desc: Use image node_id 1 to create a new BaseUnivariateDrift object from inherited base classes: BaseDetector, DriftConfigMixin with example: obj = BaseUnivariateDrift(x_ref, p_val, x_ref_preprocessed, preprocess_at_init, update_x_ref, preprocess_fn, correction, n_features, input_shape, data_type)