예제 #1
0
    def __init__(
        self,
        n_neighbors=1,
        weights="uniform",
        distance="dtw",
        distance_params=None,
        **kwargs
    ):
        self._distance_params = distance_params
        if distance_params is None:
            self._distance_params = {}
        self.distance = distance
        self.distance_params = distance_params

        if isinstance(self.distance, str):
            distance = distance_factory(metric=self.distance)

        super(KNeighborsTimeSeriesClassifier, self).__init__(
            n_neighbors=n_neighbors,
            algorithm="brute",
            metric=distance,
            metric_params=None,  # Extra distance params handled in _fit
            **kwargs
        )
        BaseClassifier.__init__(self)
        self.weights = _check_weights(weights)

        # We need to add is-fitted state when inheriting from scikit-learn
        self._is_fitted = False
예제 #2
0
    def fit(self, X, y, **kwargs):
        """Wrap fit to call BaseClassifier.fit.

        This is a fix to get around the problem with multiple inheritance. The
        problem is that if we just override _fit, this class inherits the fit from
        the sklearn class BaseTimeSeriesForest. This is the simplest solution,
        albeit a little hacky.
        """
        return BaseClassifier.fit(self, X=X, y=y, **kwargs)
예제 #3
0
 def predict_proba(self, X, **kwargs):
     """Predict proba wrapper."""
     return BaseClassifier.predict_proba(self, X, **kwargs)
예제 #4
0
 def predict(self, X, **kwargs):
     """Predict wrapper."""
     return BaseClassifier.predict(self, X, **kwargs)
예제 #5
0
 def fit(self, X, y, **kwargs):
     """Override fit is required to sort out the multiple inheritance."""
     return BaseClassifier.fit(self, X, y, **kwargs)
예제 #6
0
 def predict_proba(self, X, **kwargs) -> np.ndarray:
     """Wrap predict_proba to call BaseClassifier.predict_proba."""
     return BaseClassifier.predict_proba(self, X=X, **kwargs)
예제 #7
0
 def predict(self, X, **kwargs) -> np.ndarray:
     """Predict wrapper."""
     return BaseClassifier.predict(self, X, **kwargs)