class_docstr: Calculate trust score.
  
  Parameters
  ----------
  k_filter : int , default: 10
      Number of neighbors used during either kNN distance or probability filtering.
  alpha : float , default: 0.
      Fraction of instances to filter out to reduce impact of outliers.
  filter_type : str , default: distance_knn
      Filter method; either 'distance_knn' or 'probability_knn'
  leaf_size : int , default: 40
      Number of points at which to switch to brute-force. Affects speed and memory required to
      build trees. Memory to store the tree scales with n_samples / leaf_size.
  metric : str , default: euclidean
      Distance metric used for the tree. See sklearn's DistanceMetric class for a list of available
      metrics.
  dist_filter_type : str , default: point
      Use either the distance to the k-nearest point (dist_filter_type = 'point') or
      the average distance from the first to the k-nearest point in the data (dist_filter_type = 'mean').
class_docstr_tok: ["Calculate","trust","score",".","Parameters","--","--","--","--","--","k_filter",":","int",",","default",":","10","Number","of","neighbors","used","during","either","kNN","distance","or","probability","filtering",".","alpha",":","float",",","default",":","0",".","Fraction","of","instances","to","filter","out","to","reduce","impact","of","outliers",".","filter_type",":","str",",","default",":","distance_knn","Filter","method",";","either","'distance_knn","'","or","'probability_knn'","leaf_size",":","int",",","default",":","40","Number","of","points","at","which","to","switch","to","brute-force",".","Affects","speed","and","memory","required","to","build","trees",".","Memory","to","store","the","tree","scales","with","n_samples","\/","leaf_size",".","metric",":","str",",","default",":","euclidean","Distance","metric","used","for","the","tree",".","See","sklearn","'s","DistanceMetric","class","for","a","list","of","available","metrics",".","dist_filter_type",":","str",",","default",":","point","Use","either","the","distance","to","the","k-nearest","point","(","dist_filter_type","=","'point","'",")","or","the","average","distance","from","the","first","to","the","k-nearest","point","in","the","data","(","dist_filter_type","=","'mean","'",")","."]
docstr: Build KDTrees for each prediction class.
  
  Parameters
  ----------
  X : np.ndarray
      Data.
  Y : np.ndarray
      Target labels, either one-hot encoded or the actual class label.
docstr_tok: ["Build","KDTrees","for","each","prediction","class",".","Parameters","--","--","--","--","--","X",":","np.ndarray","Data",".","Y",":","np.ndarray","Target","labels",",","either","one-hot","encoded","or","the","actual","class","label","."]
code: def fit(self, X: np.ndarray, Y: np.ndarray) -> None:
      """Build KDTrees for each prediction class.
  
      Parameters
      ----------
      X : np.ndarray
          Data.
      Y : np.ndarray
          Target labels, either one-hot encoded or the actual class label.
      """
      if len(X.shape) > 2:
          get_logger().warning(
              "Reshaping data from %s to %s so k-d trees can be built.",
              X.shape,
              X.reshape(X.shape[0], -1).shape,
          )
          X = X.reshape(X.shape[0], -1)
  
      # make sure Y represents predicted classes, not one-hot encodings
      if len(Y.shape) > 1:
          Y = np.argmax(Y, axis=1)
          self.classes = Y.shape[1]
      else:
          self.classes = len(np.unique(Y))
      # KDTree and kNeighborsClassifier need 2D data
      self.kdtrees = [None] * self.classes
      self.X_kdtree = [None] * self.classes
  
      if self.filter == "probability_knn":
          X_filter, Y_filter = self.filter_by_probability_knn(X, Y)
  
      for c in range(self.classes):
          if self.filter is None:
              X_fit = X[np.where(Y == c)[0]]
          elif self.filter == "distance_knn":
              X_fit = self.filter_by_distance_knn(
                  X[np.where(Y == c)[0]]
              )
          elif self.filter == "probability_knn":
              X_fit = X_filter[np.where(Y_filter == c)[0]]
          else:
              raise Exception(
                  'self.filter must be one of ["distance_knn", "probability_knn", None]'
              )
  
          no_x_fit = len(X_fit) == 0
          if no_x_fit or len(X[np.where(Y == c)[0]]) == 0:
              if no_x_fit and len(X[np.where(Y == c)[0]]) == 0:
                  get_logger().warning(
                      "No instances available for class %s", c
                  )
              elif no_x_fit:
                  get_logger().warning(
                      "Filtered all the instances for class %s. Lower alpha or check data.",
                      c,
                  )
          else:
              self.kdtrees[c] = KDTree(
                  X_fit, leaf_size=self.leaf_size, metric=self.metric
              )  # build KDTree for class c
              self.X_kdtree[c] = X_fit
  
file_path: deepchecks/deepchecks/utils/distribution/trust_score.py
imports: from typing import Tuple
  import numpy
  from sklearn.neighbors import KDTree, KNeighborsClassifier
  from deepchecks.utils.logger import get_logger
label_desc: Use image node_id 4 for calling the TrustScore obj's underlying member method code with example usage: obj.fit(X, Y) without return types