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 low kNN density.
  
  Calculate distance to k-nearest point in the data for each instance and remove instances above a cutoff
  distance.
  
  Parameters
  ----------
  X : np.ndarray
      Data to filter
  Returns
  -------
  np.ndarray
      Filtered data
docstr_tok: ["Filter","out","instances","with","low","kNN","density",".","Calculate","distance","to","k-nearest","point","in","the","data","for","each","instance","and","remove","instances","above","a","cutoff","distance",".","Parameters","--","--","--","--","--","X",":","np.ndarray","Data","to","filter","Returns","--","--","--","-","np.ndarray","Filtered","data"]
code: def filter_by_distance_knn(self, X: np.ndarray) -> np.ndarray:
      """Filter out instances with low kNN density.
  
      Calculate distance to k-nearest point in the data for each instance and remove instances above a cutoff
      distance.
  
      Parameters
      ----------
      X : np.ndarray
          Data to filter
      Returns
      -------
      np.ndarray
          Filtered data
      """
      kdtree = KDTree(X, leaf_size=self.leaf_size, metric=self.metric)
      k = min(self.k_filter + 1, len(X))
      knn_r = kdtree.query(X, k=k)[
          0
      ]  # distances from 0 to k-nearest points
      if self.dist_filter_type == "point":
          knn_r = knn_r[:, -1]
      elif self.dist_filter_type == "mean":
          knn_r = np.mean(
              knn_r[:, 1:], axis=1
          )  # exclude distance of instance to itself
      cutoff_r = np.percentile(
          knn_r, (1 - self.alpha) * 100
      )  # cutoff distance
      X_keep = X[
          np.where(knn_r <= cutoff_r)[0], :
      ]  # define instances to keep
      return X_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 2 for calling the TrustScore obj's underlying member method code with example usage: obj.filter_by_distance_knn(X) and returns: X_keep