code: def _kneighbors(
      self, X=None, n_neighbors=None, return_distance=True, queue=None
  ):
      n_features = getattr(self, "n_features_in_", None)
      shape = getattr(X, "shape", None)
      if (
          n_features
          and shape
          and len(shape) > 1
          and shape[1] != n_features
      ):
          raise ValueError(
              (
                  f"X has {X.shape[1]} features, "
                  f"but kneighbors is expecting "
                  f"{n_features} features as input"
              )
          )
  
      _check_is_fitted(self)
  
      if n_neighbors is None:
          n_neighbors = self.n_neighbors
      elif n_neighbors <= 0:
          raise ValueError(
              "Expected n_neighbors > 0. Got %d" % n_neighbors
          )
      else:
          if not isinstance(n_neighbors, Integral):
              raise TypeError(
                  "n_neighbors does not take %s value, "
                  "enter integer value" % type(n_neighbors)
              )
  
      if X is not None:
          query_is_train = False
          X = _check_array(
              X, accept_sparse="csr", dtype=[np.float64, np.float32]
          )
      else:
          query_is_train = True
          X = self._fit_X
          # Include an extra neighbor to account for the sample itself being
          # returned, which is removed later
          n_neighbors += 1
      self.n_neighbors = n_neighbors
  
      n_samples_fit = self.n_samples_fit_
      if n_neighbors > n_samples_fit:
          raise ValueError(
              "Expected n_neighbors <= n_samples, "
              " but n_samples = %d, n_neighbors = %d"
              % (n_samples_fit, n_neighbors)
          )
  
      chunked_results = None
      method = super()._parse_auto_method(
          self._fit_method, self.n_samples_fit_, n_features
      )
  
      gpu_device = queue is not None and queue.sycl_device.is_gpu
      if self.effective_metric_ == "euclidean" and not gpu_device:
          params = super()._get_daal_params(X)
      else:
          params = super()._get_onedal_params(X)
  
      prediction_results = self._onedal_predict(
          self._onedal_model, X, params, queue=queue
      )
  
      if self.effective_metric_ == "euclidean" and not gpu_device:
          distances = prediction_results.distances
          indices = prediction_results.indices
      else:
          distances = from_table(prediction_results.distances)
          indices = from_table(prediction_results.indices)
  
      if method == "kd_tree":
          for i in range(distances.shape[0]):
              seq = distances[i].argsort()
              indices[i] = indices[i][seq]
              distances[i] = distances[i][seq]
  
      if return_distance:
          results = distances, indices
      else:
          results = indices
  
      if chunked_results is not None:
          if return_distance:
              neigh_dist, neigh_ind = zip(*chunked_results)
              results = np.vstack(neigh_dist), np.vstack(neigh_ind)
          else:
              results = np.vstack(chunked_results)
  
      if not query_is_train:
          return results
      # If the query data is the same as the indexed data, we would like
      # to ignore the first nearest neighbor of every sample, i.e
      # the sample itself.
      distances = distances[:, 1:]
      indices = indices[:, 1:]
  
      if return_distance:
          neigh_dist, neigh_ind = results
      else:
          neigh_ind = results
  
      n_queries, _ = X.shape
      sample_range = np.arange(n_queries)[:, None]
      sample_mask = neigh_ind != sample_range
  
      # Corner case: When the number of duplicates are more
      # than the number of neighbors, the first NN will not
      # be the sample, but a duplicate.
      # In that case mask the first duplicate.
      dup_gr_nbrs = np.all(sample_mask, axis=1)
      sample_mask[:, 0][dup_gr_nbrs] = False
  
      neigh_ind = np.reshape(
          neigh_ind[sample_mask], (n_queries, n_neighbors - 1)
      )
  
      if return_distance:
          neigh_dist = np.reshape(
              neigh_dist[sample_mask], (n_queries, n_neighbors - 1)
          )
          return neigh_dist, neigh_ind
      return neigh_ind
  
imports: from abc import ABCMeta
  from numbers import Integral
  import numpy
  from daal4py import bf_knn_classification_prediction, bf_knn_classification_training, kdtree_knn_classification_prediction, kdtree_knn_classification_training
  from onedal import _backend
  from ..common._estimator_checks import _check_is_fitted, _is_classifier, _is_regressor
  from ..common._mixin import ClassifierMixin, RegressorMixin
  from ..common._policy import _get_policy
  from ..datatypes import _convert_to_supported, from_table, to_table
  from ..utils import _check_array, _check_classification_targets, _check_n_features, _check_X_y, _column_or_1d, _num_samples
label_desc: Use image node_id 5 for calling the NeighborsBase obj's underlying member method code with example usage: obj._kneighbors(X, n_neighbors, return_distance, queue) and returns: neigh_ind, results, neigh_dist,  neigh_ind