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
      Data.
  
  Returns
  -------
  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
          Data.
  
      Returns
      -------
      Filtered data.
      """
      kdtree = KDTree(X, leaf_size=self.leaf_size, metric=self.metric)
      knn_r = kdtree.query(X, k=self.k_filter + 1)[
          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: alibi/alibi/confidence/trustscore.py
imports: import logging
  from typing import Any, Optional, Tuple
  import numpy
  from sklearn.neighbors import KDTree, KNeighborsClassifier
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