class_docstr: KNN Time Series Classifier.
  
  An adapted version of the scikit-learn KNeighborsClassifier for time series data.
  
  This class is a KNN classifier which supports time series distance measures.
  It has hardcoded string references to numba based distances in sktime.distances,
  and can also be used with callables, or sktime (pairwise transformer) estimators.
  
  Parameters
  ----------
  n_neighbors : int, set k for knn (default =1)
  weights : {'uniform', 'distance'} or callable, default='uniform'
      Weight function used in prediction.  Possible values:
      - 'uniform' : uniform weights.  All points in each neighborhood
        are weighted equally.
      - 'distance' : weight points by the inverse of their distance.
        in this case, closer neighbors of a query point will have a
        greater influence than neighbors which are further away.
      - [callable] : a user-defined function which accepts an
        array of distances, and returns an array of the same shape
        containing the weights.
  algorithm : str, optional. default = 'brute'
      search method for neighbours
      one of {'auto', 'ball_tree', 'kd_tree', 'brute'}
  distance : str or callable, optional. default ='dtw'
      distance measure between time series
      if str, must be one of the following strings:
          'euclidean', 'squared', 'dtw', 'ddtw', 'wdtw', 'wddtw',
          'lcss', 'edr', 'erp', 'msm', 'twe'
      this will substitute a hard-coded distance metric from sktime.distances
      If non-class callable, parameters can be passed via distance_params
          Example: knn_dtw = KNeighborsTimeSeriesClassifier(
                                  distance='dtw', distance_params={'epsilon':0.1})
      if any callable, must be of signature (X: Panel, X2: Panel) -> np.ndarray
          output must be mxn array if X is Panel of m Series, X2 of n Series
          if distance_mtype is not set, must be able to take
              X, X2 which are pd_multiindex and numpy3D mtype
      can be pairwise panel transformer inheriting from BasePairwiseTransformerPanel
  distance_params : dict, optional. default = None.
      dictionary for distance parameters, in case that distance is a str or callable
  distance_mtype : str, or list of str optional. default = None.
      mtype that distance expects for X and X2, if a callable
          only set this if distance is not BasePairwiseTransformerPanel descendant
  pass_train_distances : bool, optional, default = False.
      Whether distances between training points are computed and passed to sklearn.
      Passing is superfluous for algorithm='brute', but may have impact otherwise.
  leaf_size : int, default=30
      Leaf size passed to BallTree or KDTree.  This can affect the
      speed of the construction and query, as well as the memory
      required to store the tree.  The optimal value depends on the
      nature of the problem.
  n_jobs : int, default=None
      The number of parallel jobs to run for neighbors search.
      ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
      ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
      for more details.
      Doesn't affect :meth:`fit` method.
  
  Examples
  --------
  >>> from sktime.classification.distance_based import KNeighborsTimeSeriesClassifier
  >>> from sktime.datasets import load_unit_test
  >>> X_train, y_train = load_unit_test(return_X_y=True, split="train")
  >>> X_test, y_test = load_unit_test(return_X_y=True, split="test")
  >>> classifier = KNeighborsTimeSeriesClassifier(distance="euclidean")
  >>> classifier.fit(X_train, y_train)
  KNeighborsTimeSeriesClassifier(...)
  >>> y_pred = classifier.predict(X_test)
class_docstr_tok: ["KNN","Time","Series","Classifier",".","An","adapted","version","of","the","scikit-learn","KNeighborsClassifier","for","time","series","data",".","This","class","is","a","KNN","classifier","which","supports","time","series","distance","measures",".","It","has","hardcoded","string","references","to","numba","based","distances","in","sktime.distances",",","and","can","also","be","used","with","callables",",","or","sktime","(","pairwise","transformer",")","estimators",".","Parameters","--","--","--","--","--","n_neighbors",":","int",",","set","k","for","knn","(","default","=1",")","weights",":","{","'uniform","'",",","'distance","'","}","or","callable",",","default='uniform'","Weight","function","used","in","prediction",".","Possible","values",":","-","'uniform","'",":","uniform","weights",".","All","points","in","each","neighborhood","are","weighted","equally",".","-","'distance","'",":","weight","points","by","the","inverse","of","their","distance",".","in","this","case",",","closer","neighbors","of","a","query","point","will","have","a","greater","influence","than","neighbors","which","are","further","away",".","-","[","callable","]",":","a","user-defined","function","which","accepts","an","array","of","distances",",","and","returns","an","array","of","the","same","shape","containing","the","weights",".","algorithm",":","str",",","optional",".","default","=","'brute'","search","method","for","neighbours","one","of","{","'auto","'",",","'ball_tree","'",",","'kd_tree","'",",","'brute","'","}","distance",":","str","or","callable",",","optional",".","default","='dtw'","distance","measure","between","time","series","if","str",",","must","be","one","of","the","following","strings",":","'euclidean","'",",","'squared","'",",","'dtw","'",",","'ddtw","'",",","'wdtw","'",",","'wddtw","'",",","'lcss","'",",","'edr","'",",","'erp","'",",","'msm","'",",","'twe'","this","will","substitute","a","hard-coded","distance","metric","from","sktime.distances","If","non-class","callable",",","parameters","can","be","passed","via","distance_params","Example",":","knn_dtw","=","KNeighborsTimeSeriesClassifier","(","distance='dtw","'",",","distance_params=","{","'epsilon':0.1","}",")","if","any","callable",",","must","be","of","signature","(","X",":","Panel",",","X2",":","Panel",")","-",">","np.ndarray","output","must","be","mxn","array","if","X","is","Panel","of","m","Series",",","X2","of","n","Series","if","distance_mtype","is","not","set",",","must","be","able","to","take","X",",","X2","which","are","pd_multiindex","and","numpy3D","mtype","can","be","pairwise","panel","transformer","inheriting","from","BasePairwiseTransformerPanel","distance_params",":","dict",",","optional",".","default","=","None",".","dictionary","for","distance","parameters",",","in","case","that","distance","is","a","str","or","callable","distance_mtype",":","str",",","or","list","of","str","optional",".","default","=","None",".","mtype","that","distance","expects","for","X","and","X2",",","if","a","callable","only","set","this","if","distance","is","not","BasePairwiseTransformerPanel","descendant","pass_train_distances",":","bool",",","optional",",","default","=","False",".","Whether","distances","between","training","points","are","computed","and","passed","to","sklearn",".","Passing","is","superfluous","for","algorithm='brute","'",",","but","may","have","impact","otherwise",".","leaf_size",":","int",",","default=30","Leaf","size","passed","to","BallTree","or","KDTree",".","This","can","affect","the","speed","of","the","construction","and","query",",","as","well","as","the","memory","required","to","store","the","tree",".","The","optimal","value","depends","on","the","nature","of","the","problem",".","n_jobs",":","int",",","default=None","The","number","of","parallel","jobs","to","run","for","neighbors","search",".","``","None","``","means","1","unless","in","a",":","obj",":","`","joblib.parallel_backend","`","context",".","``","-1","``","means","using","all","processors",".","See",":","term",":","`","Glossary","<","n_jobs",">","`","for","more","details",".","Does","n't","affect",":","meth",":","`","fit","`","method",".","Examples","--","--","--","--",">",">",">","from","sktime.classification.distance_based","import","KNeighborsTimeSeriesClassifier",">",">",">","from","sktime.datasets","import","load_unit_test",">",">",">","X_train",",","y_train","=","load_unit_test","(","return_X_y=True",",","split=","''","train","''",")",">",">",">","X_test",",","y_test","=","load_unit_test","(","return_X_y=True",",","split=","''","test","''",")",">",">",">","classifier","=","KNeighborsTimeSeriesClassifier","(","distance=","''","euclidean","''",")",">",">",">","classifier.fit","(","X_train",",","y_train",")","KNeighborsTimeSeriesClassifier","(","...",")",">",">",">","y_pred","=","classifier.predict","(","X_test",")"]
docstr: Compute distance - unified interface to str code and callable.
docstr_tok: ["Compute","distance","-","unified","interface","to","str","code","and","callable","."]
code: def _distance(self, X, X2=None):
      """Compute distance - unified interface to str code and callable."""
      distance = self.distance
      distance_params = self.distance_params
      if distance_params is None:
          distance_params = {}
  
      if isinstance(distance, str):
          return pairwise_distance(X, X2, distance, **distance_params)
      else:
          if X2 is not None:
              return distance(X, X2, **distance_params)
          # if X2 is None, check if distance allows None X2 to mean "X2=X"
          else:
              sig = signature(distance).parameters
              X2_sig = sig[list(sig.keys())[1]]
              if X2_sig.default is not None:
                  return distance(X, X2, **distance_params)
              else:
                  return distance(X, **distance_params)
  
file_path: sktime/sktime/classification/distance_based/_time_series_neighbors.py
imports: from inspect import signature
  import numpy
  from sklearn.neighbors import KNeighborsClassifier
  from sktime.classification.base import BaseClassifier
  from sktime.datatypes import check_is_mtype
  from sktime.distances import pairwise_distance
label_desc: Use image node_id 2 for calling the KNeighborsTimeSeriesClassifier obj's underlying member method code with example usage: obj._distance(X, X2) and returns: pairwise_distance, distance, distance, distance