code: def _fit(self, X, y, queue):
      self._onedal_model = None
      self._tree = None
      self._shape = None
      self.classes_ = None
      self.effective_metric_ = getattr(
          self, "effective_metric_", self.metric
      )
      self.effective_metric_params_ = getattr(
          self, "effective_metric_params_", self.metric_params
      )
  
      if y is not None or self.requires_y:
          shape = getattr(y, "shape", None)
          X, y = super()._validate_data(
              X, y, dtype=[np.float64, np.float32], accept_sparse="csr"
          )
          self._shape = shape if shape is not None else y.shape
  
          if _is_classifier(self):
              if y.ndim == 1 or y.ndim == 2 and y.shape[1] == 1:
                  self.outputs_2d_ = False
                  y = y.reshape((-1, 1))
              else:
                  self.outputs_2d_ = True
  
              _check_classification_targets(y)
              self.classes_ = []
              self._y = np.empty(y.shape, dtype=int)
              for k in range(self._y.shape[1]):
                  classes, self._y[:, k] = np.unique(
                      y[:, k], return_inverse=True
                  )
                  self.classes_.append(classes)
  
              if not self.outputs_2d_:
                  self.classes_ = self.classes_[0]
                  self._y = self._y.ravel()
  
              self._validate_n_classes()
          else:
              self._y = y
      else:
          X, _ = super()._validate_data(
              X, dtype=[np.float64, np.float32]
          )
  
      self.n_samples_fit_ = X.shape[0]
      self.n_features_in_ = X.shape[1]
      self._fit_X = X
  
      if self.n_neighbors is not None:
          if self.n_neighbors <= 0:
              raise ValueError(
                  "Expected n_neighbors > 0. Got %d" % self.n_neighbors
              )
          if not isinstance(self.n_neighbors, Integral):
              raise TypeError(
                  "n_neighbors does not take %s value, "
                  "enter integer value" % type(self.n_neighbors)
              )
  
      self._fit_method = super()._parse_auto_method(
          self.algorithm, self.n_samples_fit_, self.n_features_in_
      )
  
      _fit_y = None
      gpu_device = queue is not None and queue.sycl_device.is_gpu
  
      if _is_classifier(self) or (_is_regressor(self) and gpu_device):
          _fit_y = self._validate_targets(self._y, X.dtype).reshape(
              (-1, 1)
          )
      result = self._onedal_fit(X, _fit_y, queue)
  
      if y is not None and _is_regressor(self):
          self._y = y if self._shape is None else y.reshape(self._shape)
  
      self._onedal_model = result
      result = self
  
      return result
  
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 4 for calling the NeighborsBase obj's underlying member method code with example usage: obj._fit(X, y, queue) and returns: result