docstr: Classifier-based drift detector. The classifier is trained on a fraction of the combined
  reference and test data and drift is detected on the remaining data. To use all the data
  to detect drift, a stratified cross-validation scheme can be chosen.
  
  Parameters
  ----------
  x_ref
      Data used as reference distribution.
  model
      Sklearn classification model used for drift detection.
  p_val
      p-value used for the significance of the test.
  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.
  preds_type
      Whether the model outputs 'probs' or 'scores'.
  binarize_preds
      Whether to test for discrepancy on soft (e.g. probs/scores) model predictions directly
      with a K-S test or binarise to 0-1 prediction errors and apply a binomial test.
  train_size
      Optional fraction (float between 0 and 1) of the dataset used to train the classifier.
      The drift is detected on `1 - train_size`. Cannot be used in combination with `n_folds`.
  n_folds
      Optional number of stratified folds used for training. The model preds are then calculated
      on all the out-of-fold predictions. This allows to leverage all the reference and test data
      for drift detection at the expense of longer computation. If both `train_size` and `n_folds`
      are specified, `n_folds` is prioritized.
  retrain_from_scratch
      Whether the classifier should be retrained from scratch for each set of test data or whether
      it should instead continue training from where it left off on the previous set.
  seed
      Optional random seed for fold selection.
  use_calibration
      Whether to use calibration. Whether to use calibration. Calibration can be used on top of any model.
  calibration_kwargs
      Optional additional kwargs for calibration.
      See https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html
      for more details.
  use_oob
      Whether to use out-of-bag(OOB) predictions. Supported only for `RandomForestClassifier`.
  input_shape
      Shape of input data.
  data_type
      Optionally specify the data type (tabular, image or time-series). Added to metadata.
docstr_tok: ["Classifier-based","drift","detector",".","The","classifier","is","trained","on","a","fraction","of","the","combined","reference","and","test","data","and","drift","is","detected","on","the","remaining","data",".","To","use","all","the","data","to","detect","drift",",","a","stratified","cross-validation","scheme","can","be","chosen",".","Parameters","--","--","--","--","--","x_ref","Data","used","as","reference","distribution",".","model","Sklearn","classification","model","used","for","drift","detection",".","p_val","p-value","used","for","the","significance","of","the","test",".","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",".","preds_type","Whether","the","model","outputs","'probs","'","or","'scores","'",".","binarize_preds","Whether","to","test","for","discrepancy","on","soft","(","e.g",".","probs\/scores",")","model","predictions","directly","with","a","K-S","test","or","binarise","to","0-1","prediction","errors","and","apply","a","binomial","test",".","train_size","Optional","fraction","(","float","between","0","and","1",")","of","the","dataset","used","to","train","the","classifier",".","The","drift","is","detected","on","`","1","-","train_size","`",".","Can","not","be","used","in","combination","with","`","n_folds","`",".","n_folds","Optional","number","of","stratified","folds","used","for","training",".","The","model","preds","are","then","calculated","on","all","the","out-of-fold","predictions",".","This","allows","to","leverage","all","the","reference","and","test","data","for","drift","detection","at","the","expense","of","longer","computation",".","If","both","`","train_size","`","and","`","n_folds","`","are","specified",",","`","n_folds","`","is","prioritized",".","retrain_from_scratch","Whether","the","classifier","should","be","retrained","from","scratch","for","each","set","of","test","data","or","whether","it","should","instead","continue","training","from","where","it","left","off","on","the","previous","set",".","seed","Optional","random","seed","for","fold","selection",".","use_calibration","Whether","to","use","calibration",".","Whether","to","use","calibration",".","Calibration","can","be","used","on","top","of","any","model",".","calibration_kwargs","Optional","additional","kwargs","for","calibration",".","See","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.calibration.CalibratedClassifierCV.html","for","more","details",".","use_oob","Whether","to","use","out-of-bag","(","OOB",")","predictions",".","Supported","only","for","`","RandomForestClassifier","`",".","input_shape","Shape","of","input","data",".","data_type","Optionally","specify","the","data","type","(","tabular",",","image","or","time-series",")",".","Added","to","metadata","."]
code: def __init__(
      self,
      x_ref: np.ndarray,
      model: ClassifierMixin,
      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,
      preds_type: str = "probs",
      binarize_preds: bool = False,
      train_size: Optional[float] = 0.75,
      n_folds: Optional[int] = None,
      retrain_from_scratch: bool = True,
      seed: int = 0,
      use_calibration: bool = False,
      calibration_kwargs: Optional[dict] = None,
      use_oob: bool = False,
      input_shape: Optional[tuple] = None,
      data_type: Optional[str] = None,
  ) -> None:
      """
      Classifier-based drift detector. The classifier is trained on a fraction of the combined
      reference and test data and drift is detected on the remaining data. To use all the data
      to detect drift, a stratified cross-validation scheme can be chosen.
  
      Parameters
      ----------
      x_ref
          Data used as reference distribution.
      model
          Sklearn classification model used for drift detection.
      p_val
          p-value used for the significance of the test.
      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.
      preds_type
          Whether the model outputs 'probs' or 'scores'.
      binarize_preds
          Whether to test for discrepancy on soft (e.g. probs/scores) model predictions directly
          with a K-S test or binarise to 0-1 prediction errors and apply a binomial test.
      train_size
          Optional fraction (float between 0 and 1) of the dataset used to train the classifier.
          The drift is detected on `1 - train_size`. Cannot be used in combination with `n_folds`.
      n_folds
          Optional number of stratified folds used for training. The model preds are then calculated
          on all the out-of-fold predictions. This allows to leverage all the reference and test data
          for drift detection at the expense of longer computation. If both `train_size` and `n_folds`
          are specified, `n_folds` is prioritized.
      retrain_from_scratch
          Whether the classifier should be retrained from scratch for each set of test data or whether
          it should instead continue training from where it left off on the previous set.
      seed
          Optional random seed for fold selection.
      use_calibration
          Whether to use calibration. Whether to use calibration. Calibration can be used on top of any model.
      calibration_kwargs
          Optional additional kwargs for calibration.
          See https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html
          for more details.
      use_oob
          Whether to use out-of-bag(OOB) predictions. Supported only for `RandomForestClassifier`.
      input_shape
          Shape of input data.
      data_type
          Optionally specify the data type (tabular, image or time-series). Added to metadata.
      """
      super().__init__(
          x_ref=x_ref,
          p_val=p_val,
          x_ref_preprocessed=x_ref_preprocessed,
          preprocess_at_init=preprocess_at_init,
          update_x_ref=update_x_ref,
          preprocess_fn=preprocess_fn,
          preds_type=preds_type,
          binarize_preds=binarize_preds,
          train_size=train_size,
          n_folds=n_folds,
          retrain_from_scratch=retrain_from_scratch,
          seed=seed,
          input_shape=input_shape,
          data_type=data_type,
      )
  
      if preds_type not in ["probs", "scores"]:
          raise ValueError("'preds_type' should be 'probs' or 'scores'")
  
      self.meta.update({"backend": Framework.SKLEARN.value})
      self.original_model = model
      self.use_calibration = use_calibration
      self.calibration_kwargs = (
          dict() if calibration_kwargs is None else calibration_kwargs
      )
      self.use_oob = use_oob
      self.model: ClassifierMixin = self._clone_model()
  
file_path: alibi-detect/alibi_detect/cd/sklearn/classifier.py
imports: import logging
  import numpy
  from functools import partial
  from typing import Callable, Dict, Optional, Tuple, Union
  from sklearn.base import clone, ClassifierMixin
  from sklearn.calibration import CalibratedClassifierCV
  from sklearn.exceptions import NotFittedError
  from sklearn.ensemble import RandomForestClassifier
  from alibi_detect.cd.base import BaseClassifierDrift
  from alibi_detect.utils.warnings import deprecated_alias
  from alibi_detect.utils.frameworks import Framework
label_desc: Use image node_id 1 to create a new ClassifierDriftSklearn object from inherited base classes: BaseClassifierDrift with example: obj = ClassifierDriftSklearn(x_ref, model, p_val, x_ref_preprocessed, preprocess_at_init, update_x_ref, preprocess_fn, preds_type, binarize_preds, train_size, n_folds, retrain_from_scratch, seed, use_calibration, calibration_kwargs, use_oob, input_shape, data_type)