class_docstr: Mixin for k-neighbors searches on Time Series.
docstr: Finds the K-neighbors of a point.
  
  Returns indices of and distances to the neighbors of each point.
  
  Parameters
  ----------
  X : array-like, shape (n_ts, sz, d)
      The query time series.
      If not provided, neighbors of each indexed point are returned.
      In this case, the query point is not considered its own neighbor.
  n_neighbors : int
      Number of neighbors to get (default is the value passed to the
      constructor).
  return_distance : boolean, optional. Defaults to True.
      If False, distances will not be returned
  
  Returns
  -------
  dist : array
      Array representing the distance to points, only present if
      return_distance=True
  ind : array
      Indices of the nearest points in the population matrix.
docstr_tok: ["Finds","the","K-neighbors","of","a","point",".","Returns","indices","of","and","distances","to","the","neighbors","of","each","point",".","Parameters","--","--","--","--","--","X",":","array-like",",","shape","(","n_ts",",","sz",",","d",")","The","query","time","series",".","If","not","provided",",","neighbors","of","each","indexed","point","are","returned",".","In","this","case",",","the","query","point","is","not","considered","its","own","neighbor",".","n_neighbors",":","int","Number","of","neighbors","to","get","(","default","is","the","value","passed","to","the","constructor",")",".","return_distance",":","boolean",",","optional",".","Defaults","to","True",".","If","False",",","distances","will","not","be","returned","Returns","--","--","--","-","dist",":","array","Array","representing","the","distance","to","points",",","only","present","if","return_distance=True","ind",":","array","Indices","of","the","nearest","points","in","the","population","matrix","."]
code: def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
      """Finds the K-neighbors of a point.
  
      Returns indices of and distances to the neighbors of each point.
  
      Parameters
      ----------
      X : array-like, shape (n_ts, sz, d)
          The query time series.
          If not provided, neighbors of each indexed point are returned.
          In this case, the query point is not considered its own neighbor.
      n_neighbors : int
          Number of neighbors to get (default is the value passed to the
          constructor).
      return_distance : boolean, optional. Defaults to True.
          If False, distances will not be returned
  
      Returns
      -------
      dist : array
          Array representing the distance to points, only present if
          return_distance=True
      ind : array
          Indices of the nearest points in the population matrix.
      """
      self_neighbors = False
      if n_neighbors is None:
          n_neighbors = self.n_neighbors
      if X is None:
          X = self._X_fit
          self_neighbors = True
      if self.metric == "precomputed":
          full_dist_matrix = X
      else:
          if X.ndim == 2:  # sklearn-format case
              X = X.reshape((X.shape[0], -1, self._d))
              fit_X = self._X_fit.reshape(
                  (self._X_fit.shape[0], -1, self._d)
              )
          elif hasattr(self, "_ts_fit") and self._ts_fit is not None:
              fit_X = self._ts_fit
          else:
              fit_X = self._X_fit
  
          if self.metric in TSLEARN_VALID_METRICS or self.metric in [
              cdist_dtw,
              cdist_ctw,
              cdist_soft_dtw,
              cdist_sax,
          ]:
              full_dist_matrix = self._precompute_cross_dist(
                  X, other_X=fit_X
              )
          elif self.metric in ["euclidean", "sqeuclidean", "cityblock"]:
              full_dist_matrix = scipy_cdist(
                  X.reshape((X.shape[0], -1)),
                  fit_X.reshape((fit_X.shape[0], -1)),
                  metric=self.metric,
              )
          else:
              raise ValueError(
                  "Unrecognized time series metric string: %s "
                  "(should be one of 'dtw', 'softdtw', "
                  "'sax', 'euclidean', 'sqeuclidean' "
                  "or 'cityblock')" % self.metric
              )
  
      # Code similar to sklearn (sklearn/neighbors/base.py), to make sure
      # that TimeSeriesKNeighbor~(metric='euclidean') has the same results as
      # feeding a distance matrix to sklearn.KNeighbors~(metric='euclidean')
      kbin = min(n_neighbors - 1, full_dist_matrix.shape[1] - 1)
      # argpartition will make sure the first `kbin` entries are the
      # `kbin` smallest ones (but in arbitrary order) --> complexity: O(n)
      ind = numpy.argpartition(full_dist_matrix, kbin, axis=1)
  
      if self_neighbors:
          ind = ind[:, 1:]
      if n_neighbors > full_dist_matrix.shape[1]:
          n_neighbors = full_dist_matrix.shape[1]
      ind = ind[:, :n_neighbors]
  
      n_ts = X.shape[0]
      sample_range = numpy.arange(n_ts)[:, None]
      # Sort the `kbin` nearest neighbors according to distance
      ind = ind[
          sample_range,
          numpy.argsort(full_dist_matrix[sample_range, ind]),
      ]
      dist = full_dist_matrix[sample_range, ind]
  
      if hasattr(self, "_ts_metric"):
          self.metric = self._ts_metric
  
      if return_distance:
          return dist, ind
      else:
          return ind
  
imports: import numpy
  from sklearn import neighbors
  from sklearn.neighbors import KNeighborsClassifier, NearestNeighbors, KNeighborsRegressor
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from scipy.spatial.distance import cdist
  from tslearn.metrics import cdist_dtw, cdist_ctw, cdist_soft_dtw, cdist_sax, TSLEARN_VALID_METRICS
  from tslearn.piecewise import SymbolicAggregateApproximation
  from tslearn.utils import to_time_series_dataset, to_sklearn_dataset, check_dims
  from tslearn.bases import BaseModelPackage
label_desc: Use image node_id 4 for calling the KNeighborsTimeSeriesMixin obj's underlying member method code with example usage: obj.kneighbors(X, n_neighbors, return_distance) and returns: dist,  ind, ind