docstr: Compute the out-of-fold drift metric such as the accuracy from a classifier
  trained to distinguish the reference data from the data to be tested.
  
  Parameters
  ----------
  x
      Batch of instances.
  
  Returns
  -------
  p-value, a notion of distance between the trained classifier's out-of-fold performance         and that which we'd expect under the null assumption of no drift,         and the out-of-fold classifier model prediction probabilities on the reference and test data         as well as the associated reference and test instances of the out-of-fold predictions.
docstr_tok: ["Compute","the","out-of-fold","drift","metric","such","as","the","accuracy","from","a","classifier","trained","to","distinguish","the","reference","data","from","the","data","to","be","tested",".","Parameters","--","--","--","--","--","x","Batch","of","instances",".","Returns","--","--","--","-","p-value",",","a","notion","of","distance","between","the","trained","classifier","'s","out-of-fold","performance","and","that","which","we","'d","expect","under","the","null","assumption","of","no","drift",",","and","the","out-of-fold","classifier","model","prediction","probabilities","on","the","reference","and","test","data","as","well","as","the","associated","reference","and","test","instances","of","the","out-of-fold","predictions","."]
code: def score(
      self, x: np.ndarray
  ) -> Tuple[
      float,
      float,
      np.ndarray,
      np.ndarray,  # type: ignore[override]
      Union[np.ndarray, list],
      Union[np.ndarray, list],
  ]:
      """
          Compute the out-of-fold drift metric such as the accuracy from a classifier
          trained to distinguish the reference data from the data to be tested.
  
          Parameters
          ----------
          x
              Batch of instances.
  
          Returns
          -------
          p-value, a notion of distance between the trained classifier's out-of-fold performance \
          and that which we'd expect under the null assumption of no drift, \
          and the out-of-fold classifier model prediction probabilities on the reference and test data \
          as well as the associated reference and test instances of the out-of-fold predictions.
          """
      x_ref, x = self.preprocess(x)  # type: ignore[assignment]
      x, y, splits = self.get_splits(x_ref, x)  # type: ignore
  
      # iterate over folds: train a new model for each fold and make out-of-fold (oof) predictions
      preds_oof_list, idx_oof_list = [], []
      for idx_tr, idx_te in splits:
          y_tr = np.eye(2)[y[idx_tr]]
          if isinstance(x, np.ndarray):
              x_tr, x_te = x[idx_tr], x[idx_te]
          elif isinstance(x, list):
              x_tr, x_te = [x[_] for _ in idx_tr], [
                  x[_] for _ in idx_te
              ]
          else:
              raise TypeError(
                  f"x needs to be of type np.ndarray or list and not {type(x)}."
              )
          ds_tr = self.dataset(x_tr, y_tr)
          if self.retrain_from_scratch:
              # clone model to re-initialise
              self.model = clone_model(self.original_model)
              # Clone optimizer to prevent error due to cloned model (with new tf>=2.11 optimizers)
              optimizer = self.train_kwargs["optimizer"]
              self.train_kwargs[
                  "optimizer"
              ] = optimizer.__class__.from_config(
                  optimizer.get_config()
              )
          train_args = [self.model, self.loss_fn, None]
          self.train_kwargs.update({"dataset": ds_tr})
          trainer(*train_args, **self.train_kwargs)
          preds = self.predict_fn(x_te, self.model)
          preds_oof_list.append(preds)
          idx_oof_list.append(idx_te)
      preds_oof = np.concatenate(preds_oof_list, axis=0)
      probs_oof = (
          softmax(preds_oof, axis=-1)
          if self.preds_type == "logits"
          else preds_oof
      )
      idx_oof = np.concatenate(idx_oof_list, axis=0)
      y_oof = y[idx_oof]
      n_cur = y_oof.sum()
      n_ref = len(y_oof) - n_cur
      p_val, dist = self.test_probs(y_oof, probs_oof, n_ref, n_cur)
      idx_sort = np.argsort(idx_oof)
      probs_sort = probs_oof[idx_sort]
      if isinstance(x, np.ndarray):
          x_oof = x[idx_oof]
          x_sort = x_oof[idx_sort]
      else:
          x_oof = [x[_] for _ in idx_oof]
          x_sort = [x_oof[_] for _ in idx_sort]
      return (
          p_val,
          dist,
          probs_sort[:n_ref, 1],
          probs_sort[n_ref:, 1],
          x_sort[:n_ref],
          x_sort[n_ref:],
      )
  
file_path: alibi-detect/alibi_detect/cd/tensorflow/classifier.py
imports: from functools import partial
  import numpy
  import tensorflow
  from tensorflow.keras.losses import BinaryCrossentropy
  from scipy.special import softmax
  from typing import Callable, Dict, Optional, Tuple, Union
  from alibi_detect.cd.base import BaseClassifierDrift
  from alibi_detect.models.tensorflow.trainer import trainer
  from alibi_detect.utils.tensorflow.data import TFDataset
  from alibi_detect.utils.tensorflow.misc import clone_model
  from alibi_detect.utils.tensorflow.prediction import predict_batch
  from alibi_detect.utils.warnings import deprecated_alias
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.utils._types import OptimizerTF
label_desc: Use image node_id 2 for calling the ClassifierDriftTF obj's underlying member method code with example usage: obj.score(x) and returns: p_val,  dist,  probs_sort,  probs_sort,  x_sort,  x_sort