diff --git a/skfda/_utils/_neighbors_base.py b/skfda/_utils/_neighbors_base.py index c6b97bba2..fcf1ea880 100644 --- a/skfda/_utils/_neighbors_base.py +++ b/skfda/_utils/_neighbors_base.py @@ -490,8 +490,8 @@ def radius_neighbors_graph( class NeighborsClassifierMixin( - NeighborsBase[Input, TargetClassification], ClassifierMixin[Input, TargetClassification], + NeighborsBase[Input, TargetClassification], ): """Mixin class for classifiers based in nearest neighbors.""" @@ -572,8 +572,8 @@ def fit( class NeighborsRegressorMixin( - NeighborsBase[Input, TargetRegression], RegressorMixin[Input, TargetRegression], + NeighborsBase[Input, TargetRegression], ): """Mixin class for the regressors based on neighbors.""" diff --git a/skfda/_utils/_sklearn_adapter.py b/skfda/_utils/_sklearn_adapter.py index f3eaecb0b..38e1df7fb 100644 --- a/skfda/_utils/_sklearn_adapter.py +++ b/skfda/_utils/_sklearn_adapter.py @@ -28,8 +28,8 @@ class BaseEstimator( # noqa: D101 class TransformerMixin( # noqa: D101 ABC, - Generic[Input, Output, Target], sklearn.base.TransformerMixin, # type: ignore[misc] + Generic[Input, Output, Target], ): @overload @@ -52,6 +52,10 @@ def fit( # noqa: D102 X: Input, y: Target | None = None, ) -> SelfType: + fit = getattr(super(), "fit", None) + if fit: + return super().fit(X, y) + return self @overload @@ -75,6 +79,10 @@ def fit_transform( # noqa: D102 y: Target | None = None, **fit_params: Any, ) -> Output: + fit_transform = getattr(super(), "fit_transform", None) + if fit_transform: + return fit_transform(X, y, **fit_params) + if y is None: return self.fit( # type: ignore[no-any-return] X, @@ -97,13 +105,13 @@ def transform( # noqa: D102 self: SelfType, X: Input, ) -> Output: - pass + return super().transform(X) class OutlierMixin( # noqa: D101 ABC, - Generic[Input], sklearn.base.OutlierMixin, # type: ignore[misc] + Generic[Input], ): def fit_predict( # noqa: D102 @@ -111,19 +119,27 @@ def fit_predict( # noqa: D102 X: Input, y: object = None, ) -> NDArrayInt: + fit_predict = getattr(super(), "fit_predict", None) + if fit_predict: + return fit_predict(X, y) + return self.fit(X, y).predict(X) # type: ignore[no-any-return] class ClassifierMixin( # noqa: D101 ABC, - Generic[Input, TargetPrediction], sklearn.base.ClassifierMixin, # type: ignore[misc] + Generic[Input, TargetPrediction], ): def fit( # noqa: D102 self: SelfType, X: Input, y: TargetPrediction, ) -> SelfType: + fit = getattr(super(), "fit", None) + if fit: + return super().fit(X, y) + return self @abstractmethod @@ -131,7 +147,7 @@ def predict( # noqa: D102 self: SelfType, X: Input, ) -> TargetPrediction: - pass + return super().predict(X) def score( # noqa: D102 self, @@ -148,8 +164,8 @@ def score( # noqa: D102 class ClusterMixin( # noqa: D101 ABC, - Generic[Input], sklearn.base.ClusterMixin, # type: ignore[misc] + Generic[Input], ): def fit_predict( # noqa: D102 self, @@ -161,14 +177,18 @@ def fit_predict( # noqa: D102 class RegressorMixin( # noqa: D101 ABC, - Generic[Input, TargetPrediction], sklearn.base.RegressorMixin, # type: ignore[misc] + Generic[Input, TargetPrediction], ): def fit( # noqa: D102 self: SelfType, X: Input, y: TargetPrediction, ) -> SelfType: + fit = getattr(super(), "fit", None) + if fit: + return super().fit(X, y) + return self @abstractmethod @@ -176,7 +196,7 @@ def predict( # noqa: D102 self: SelfType, X: Input, ) -> TargetPrediction: - pass + return super().predict(X) def score( # noqa: D102 self, diff --git a/skfda/ml/classification/_neighbors_classifiers.py b/skfda/ml/classification/_neighbors_classifiers.py index 6a4391b97..e2d8540f2 100644 --- a/skfda/ml/classification/_neighbors_classifiers.py +++ b/skfda/ml/classification/_neighbors_classifiers.py @@ -28,8 +28,8 @@ class KNeighborsClassifier( - KNeighborsMixin[Input, NDArrayInt], NeighborsClassifierMixin[Input, NDArrayInt], + KNeighborsMixin[Input, NDArrayInt], ): """ Classifier implementing the k-nearest neighbors vote. @@ -190,8 +190,8 @@ def _init_estimator(self) -> _KNeighborsClassifier: class RadiusNeighborsClassifier( - RadiusNeighborsMixin[Input, NDArrayInt], NeighborsClassifierMixin[Input, NDArrayInt], + RadiusNeighborsMixin[Input, NDArrayInt], ): """ Classifier implementing a vote among neighbors within a given radius.