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: Filter out instances with high label disagreement amongst its k nearest neighbors.
  
  Parameters
  ----------
  X : np.ndarray
      Data
  Y : np.ndarray
      Predicted class labels
  Returns
  -------
  Tuple[np.ndarray, np.ndarray]
      Filtered data and labels.
docstr_tok: ["Filter","out","instances","with","high","label","disagreement","amongst","its","k","nearest","neighbors",".","Parameters","--","--","--","--","--","X",":","np.ndarray","Data","Y",":","np.ndarray","Predicted","class","labels","Returns","--","--","--","-","Tuple","[","np.ndarray",",","np.ndarray","]","Filtered","data","and","labels","."]
code: def filter_by_probability_knn(
      self, X: np.ndarray, Y: np.ndarray
  ) -> Tuple[np.ndarray, np.ndarray]:
      """Filter out instances with high label disagreement amongst its k nearest neighbors.
  
      Parameters
      ----------
      X : np.ndarray
          Data
      Y : np.ndarray
          Predicted class labels
      Returns
      -------
      Tuple[np.ndarray, np.ndarray]
          Filtered data and labels.
      """
      if self.k_filter == 1:
          get_logger().warning(
              "Number of nearest neighbors used for probability density filtering should "
              "be >1, otherwise the prediction probabilities are either 0 or 1 making "
              "probability filtering useless."
          )
      # fit kNN classifier and make predictions on X
      clf = KNeighborsClassifier(
          n_neighbors=self.k_filter,
          leaf_size=self.leaf_size,
          metric=self.metric,
      )
      clf.fit(X, Y)
      preds_proba = clf.predict_proba(X)
      # define cutoff and instances to keep
      preds_max = np.max(preds_proba, axis=1)
      cutoff_proba = np.percentile(
          preds_max, self.alpha * 100
      )  # cutoff probability
      keep_id = np.where(preds_max >= cutoff_proba)[
          0
      ]  # define id's of instances to keep
      X_keep, Y_keep = X[keep_id, :], Y[keep_id]
      return X_keep, Y_keep
  
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 3 for calling the TrustScore obj's underlying member method code with example usage: obj.filter_by_probability_knn(X, Y) and returns: X_keep,  Y_keep