def fit(self, X, y):
        """Fit the model according to the given training data.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_timestamps)
            Training vector.

        y : array-like, shape = (n_samples,)
            Class labels for each data sample.

        Returns
        -------
        self : object

        """
        X, y = check_X_y(X, y)
        self._le = LabelEncoder().fit(y)
        self.classes_ = self._le.classes_

        if self.metric == 'dtw':
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=dtw,
                metric_params=self.metric_params,
                n_jobs=self.n_jobs, **self.kwargs
            )

        elif self.metric == 'dtw_classic':
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=_dtw_classic,
                metric_params=self.metric_params,
                n_jobs=self.n_jobs, **self.kwargs
            )

        elif self.metric == 'dtw_sakoechiba':
            n_timestamps = X.shape[1]
            if self.metric_params is None:
                region = sakoe_chiba_band(n_timestamps)
            else:
                if 'window_size' not in self.metric_params.keys():
                    window_size = 0.1
                else:
                    window_size = self.metric_params['window_size']
                region = sakoe_chiba_band(n_timestamps,
                                          window_size=window_size)
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=_dtw_region,
                metric_params={'region': region},
                n_jobs=self.n_jobs, **self.kwargs
            )

        elif self.metric == 'dtw_itakura':
            n_timestamps = X.shape[1]
            if self.metric_params is None:
                region = itakura_parallelogram(n_timestamps)
            else:
                if 'max_slope' not in self.metric_params.keys():
                    max_slope = 2.
                else:
                    max_slope = self.metric_params['max_slope']
                region = itakura_parallelogram(n_timestamps,
                                               max_slope=max_slope)
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=_dtw_region,
                metric_params={'region': region},
                n_jobs=self.n_jobs, **self.kwargs
            )

        elif self.metric == 'dtw_multiscale':
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=_dtw_multiscale,
                metric_params=self.metric_params,
                n_jobs=self.n_jobs, **self.kwargs
            )

        elif self.metric == 'dtw_fast':
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=_dtw_fast,
                metric_params=self.metric_params,
                n_jobs=self.n_jobs, **self.kwargs
            )

        elif self.metric == 'boss':
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm='brute', metric=boss,
                metric_params=self.metric_params,
                n_jobs=self.n_jobs, **self.kwargs
            )

        else:
            self._clf = SklearnKNN(
                n_neighbors=self.n_neighbors, weights=self.weights,
                algorithm=self.algorithm, leaf_size=self.leaf_size,
                p=self.p, metric=self.metric, metric_params=self.metric_params,
                n_jobs=self.n_jobs, **self.kwargs
            )

        self._clf.fit(X, y)
        return self
Fit the model according to the given training data.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_timestamps)
            Training vector.

        y : array-like, shape = (n_samples,)
            Class labels for each data sample.

        Returns
        -------
        self : object

        
pyts/classification/knn.py