KNeighborsTimeSeriesClassifier¶
-
class
sktime.classification.distance_based.
KNeighborsTimeSeriesClassifier
(n_neighbors=1, weights='uniform', distance='dtw', distance_params=None, **kwargs)[source]¶ An adapted version of the scikit-learn KNeighborsClassifier to work with time series data.
- Necessary changes required for time series data:
calls to X.shape in kneighbors, predict and predict_proba. In the base class, these methods contain:
n_samples, _ = X.shape
This however assumes that data must be 2d (a set of multivariate time series is 3d). Therefore these methods needed to be overridden to change this call to the following to support 3d data:
n_samples = X.shape[0]
check array has been disabled. This method allows nd data via an
- argument in the method header. However, there
seems to be no way to set this in the classifier and allow it to propagate down to the method. Therefore, this method has been temporarily disabled (and then re-enabled). It is unclear how to fix this issue without either writing a new classifier from scratch or changing the scikit-learn implementation. TO-DO: find permanent resolution to this issue (raise as an issue on sklearn GitHub?)
- Parameters
n_neighbors (int, set k for knn (default =1)) –
weights (mechanism for weighting a vote: 'uniform', 'distance') –
a callable function (or) –
algorithm (search method for neighbours {‘auto’, ‘ball_tree’,) –
‘kd_tree’ (default = 'brute') –
‘brute’} (default = 'brute') –
distance (distance measure for time series: {'dtw','ddtw',) –
'wdtw' (default ='dtw') –
'lcss' (default ='dtw') –
'erp' (default ='dtw') –
'msm' (default ='dtw') –
'twe'} (default ='dtw') –
distance_params (dictionary for metric parameters: default = None) –