docstr: Compute K-S or Chi-Squared test statistics and p-values per feature.
  
  Parameters
  ----------
  x_ref
      Reference instances to compare distribution with.
  x
      Batch of instances.
  
  Returns
  -------
  Feature level p-values and K-S or Chi-Squared statistics.
docstr_tok: ["Compute","K-S","or","Chi-Squared","test","statistics","and","p-values","per","feature",".","Parameters","--","--","--","--","--","x_ref","Reference","instances","to","compare","distribution","with",".","x","Batch","of","instances",".","Returns","--","--","--","-","Feature","level","p-values","and","K-S","or","Chi-Squared","statistics","."]
code: def feature_score(
      self, x_ref: np.ndarray, x: np.ndarray
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      Compute K-S or Chi-Squared test statistics and p-values per feature.
  
      Parameters
      ----------
      x_ref
          Reference instances to compare distribution with.
      x
          Batch of instances.
  
      Returns
      -------
      Feature level p-values and K-S or Chi-Squared statistics.
      """
      x_ref = x_ref.reshape(x_ref.shape[0], -1)
      x = x.reshape(x.shape[0], -1)
  
      # apply counts on union of categories per variable in both the reference and test data
      if self.cat_vars:
          x_categories = {
              f: list(np.unique(x[:, f])) for f in self.cat_vars
          }
          all_categories = {
              f: list(set().union(self.x_ref_categories[f], x_categories[f]))  # type: ignore
              for f in self.cat_vars
          }
          x_ref_count = self._get_counts(x_ref, all_categories)
          x_count = self._get_counts(x, all_categories)
  
      p_val = np.zeros(self.n_features, dtype=np.float32)
      dist = np.zeros_like(p_val)
      for f in range(self.n_features):
          if f in self.cat_vars:
              contingency_table = np.vstack(
                  (x_ref_count[f], x_count[f])
              )
              dist[f], p_val[f], _, _ = chi2_contingency(
                  contingency_table
              )
          else:
              dist[f], p_val[f] = ks_2samp(
                  x_ref[:, f],
                  x[:, f],
                  alternative=self.alternative,
                  mode="asymp",
              )
      return p_val, dist
  
file_path: alibi-detect/alibi_detect/cd/tabular.py
imports: import numpy
  from scipy.stats import chi2_contingency, ks_2samp
  from typing import Callable, Dict, List, Optional, Tuple, Union
  from alibi_detect.cd.base import BaseUnivariateDrift
  from alibi_detect.utils.warnings import deprecated_alias
  import warnings
label_desc: Use image node_id 2 for calling the TabularDrift obj's underlying member method code with example usage: obj.feature_score(x_ref, x) and returns: p_val,  dist