diff --git a/skfda/exploratory/depth/multivariate.py b/skfda/exploratory/depth/multivariate.py index dd598f1b5..eab97073f 100644 --- a/skfda/exploratory/depth/multivariate.py +++ b/skfda/exploratory/depth/multivariate.py @@ -22,8 +22,8 @@ class _DepthOrOutlyingness( - BaseEstimator, InductiveTransformerMixin[Input, NDArrayFloat, object], + BaseEstimator, ): """Abstract class representing a depth or outlyingness function.""" diff --git a/skfda/exploratory/outliers/_boxplot.py b/skfda/exploratory/outliers/_boxplot.py index 271876a49..387dfcdb8 100644 --- a/skfda/exploratory/outliers/_boxplot.py +++ b/skfda/exploratory/outliers/_boxplot.py @@ -8,8 +8,8 @@ class BoxplotOutlierDetector( - BaseEstimator, OutlierMixin[FDataGrid], + BaseEstimator, ): r""" Outlier detector using the interquartile range. diff --git a/skfda/exploratory/outliers/_directional_outlyingness.py b/skfda/exploratory/outliers/_directional_outlyingness.py index a61512d98..9fabf6f89 100644 --- a/skfda/exploratory/outliers/_directional_outlyingness.py +++ b/skfda/exploratory/outliers/_directional_outlyingness.py @@ -238,8 +238,8 @@ def directional_outlyingness_stats( # noqa: WPS218 class MSPlotOutlierDetector( # noqa: WPS230 - BaseEstimator, OutlierMixin[FDataGrid], + BaseEstimator, ): r"""Outlier detector using directional outlyingness. diff --git a/skfda/exploratory/outliers/_outliergram.py b/skfda/exploratory/outliers/_outliergram.py index 6d67d60c8..dd7b2627d 100644 --- a/skfda/exploratory/outliers/_outliergram.py +++ b/skfda/exploratory/outliers/_outliergram.py @@ -10,8 +10,8 @@ class OutliergramOutlierDetector( - BaseEstimator, OutlierMixin[FDataGrid], + BaseEstimator, ): r""" Outlier detector using the relation between MEI and MBD. diff --git a/skfda/misc/operators/_srvf.py b/skfda/misc/operators/_srvf.py index 527ad53dd..67a5bee33 100644 --- a/skfda/misc/operators/_srvf.py +++ b/skfda/misc/operators/_srvf.py @@ -15,8 +15,8 @@ class SRSF( Operator[FDataGrid, FDataGrid], - BaseEstimator, InductiveTransformerMixin[FDataGrid, FDataGrid, object], + BaseEstimator, ): r"""Square-Root Slope Function (SRSF) transform. diff --git a/skfda/misc/scoring.py b/skfda/misc/scoring.py index 979d4ec32..706440e46 100644 --- a/skfda/misc/scoring.py +++ b/skfda/misc/scoring.py @@ -750,12 +750,17 @@ def mean_squared_error( multioutput = 'raw_values', ndarray. """ - return sklearn.metrics.mean_squared_error( # type: ignore [no-any-return] + function = ( + sklearn.metrics.mean_squared_error + if squared + else sklearn.metrics.root_mean_squared_error + ) + + return function( # type: ignore [no-any-return] y_true, y_pred, sample_weight=sample_weight, multioutput=multioutput, - squared=squared, ) @@ -919,13 +924,18 @@ def mean_squared_log_error( multioutput = 'raw_values', ndarray. """ + function = ( + sklearn.metrics.mean_squared_log_error + if squared + else sklearn.metrics.root_mean_squared_log_error + ) + return ( # type: ignore [no-any-return] - sklearn.metrics.mean_squared_log_error( + function( y_true, y_pred, sample_weight=sample_weight, multioutput=multioutput, - squared=squared, ) ) diff --git a/skfda/ml/classification/_centroid_classifiers.py b/skfda/ml/classification/_centroid_classifiers.py index 83b421100..ef72e191b 100644 --- a/skfda/ml/classification/_centroid_classifiers.py +++ b/skfda/ml/classification/_centroid_classifiers.py @@ -20,8 +20,8 @@ class NearestCentroid( - BaseEstimator, ClassifierMixin[Input, Target], + BaseEstimator, ): """ Nearest centroid classifier for functional data. diff --git a/skfda/ml/classification/_depth_classifiers.py b/skfda/ml/classification/_depth_classifiers.py index 8f0ded049..36896a1f0 100644 --- a/skfda/ml/classification/_depth_classifiers.py +++ b/skfda/ml/classification/_depth_classifiers.py @@ -64,8 +64,8 @@ def _classifier_fit_depth_methods( class DDClassifier( - BaseEstimator, ClassifierMixin[Input, Target], + BaseEstimator, ): """ Depth-versus-depth (DD) classifer for functional data. @@ -215,8 +215,8 @@ def predict(self, X: Input) -> Target: class DDGClassifier( - BaseEstimator, ClassifierMixin[Input, Target], + BaseEstimator, ): r""" Generalized depth-versus-depth (DD) classifier for functional data. @@ -451,8 +451,8 @@ def predict(self, X: Input) -> Target: class _ArgMaxClassifier( - BaseEstimator, ClassifierMixin[NDArrayFloat, Target], + BaseEstimator, ): r"""Arg max classifier for multivariate data. diff --git a/skfda/ml/classification/_logistic_regression.py b/skfda/ml/classification/_logistic_regression.py index 37ff0e4f6..3beedcd73 100644 --- a/skfda/ml/classification/_logistic_regression.py +++ b/skfda/ml/classification/_logistic_regression.py @@ -16,8 +16,8 @@ class LogisticRegression( - BaseEstimator, ClassifierMixin[FDataGrid, NDArrayAny], + BaseEstimator, ): r"""Logistic Regression classifier for functional data. diff --git a/skfda/ml/classification/_qda.py b/skfda/ml/classification/_qda.py index ffee147ee..4a89f4b73 100644 --- a/skfda/ml/classification/_qda.py +++ b/skfda/ml/classification/_qda.py @@ -17,8 +17,8 @@ class QuadraticDiscriminantAnalysis( - BaseEstimator, ClassifierMixin[FDataGrid, Target], + BaseEstimator, ): """ Functional quadratic discriminant analysis. diff --git a/skfda/ml/clustering/_kmeans.py b/skfda/ml/clustering/_kmeans.py index c433eb186..66298ed41 100644 --- a/skfda/ml/clustering/_kmeans.py +++ b/skfda/ml/clustering/_kmeans.py @@ -32,9 +32,9 @@ class BaseKMeans( - BaseEstimator, ClusterMixin[Input], TransformerMixin[Input, NDArrayFloat, object], + BaseEstimator, Generic[Input, MembershipType], ): """Base class to implement K-Means clustering algorithms. diff --git a/skfda/ml/regression/_fpca_regression.py b/skfda/ml/regression/_fpca_regression.py index 7bd39692f..4cfa3b054 100644 --- a/skfda/ml/regression/_fpca_regression.py +++ b/skfda/ml/regression/_fpca_regression.py @@ -16,8 +16,8 @@ class FPCARegression( - BaseEstimator, RegressorMixin, + BaseEstimator, ): r"""Regression using Functional Principal Components Analysis. diff --git a/skfda/ml/regression/_fpls_regression.py b/skfda/ml/regression/_fpls_regression.py index ea4dd4eac..ba6c5cec6 100644 --- a/skfda/ml/regression/_fpls_regression.py +++ b/skfda/ml/regression/_fpls_regression.py @@ -23,8 +23,8 @@ class FPLSRegression( - BaseEstimator, RegressorMixin[InputType, OutputType], + BaseEstimator, ): r""" Regression using Functional Partial Least Squares. diff --git a/skfda/ml/regression/_historical_linear_model.py b/skfda/ml/regression/_historical_linear_model.py index 4067d2359..28fb28f21 100644 --- a/skfda/ml/regression/_historical_linear_model.py +++ b/skfda/ml/regression/_historical_linear_model.py @@ -214,8 +214,8 @@ def _create_fem_basis( class HistoricalLinearRegression( - BaseEstimator, RegressorMixin[FDataGrid, FDataGrid], + BaseEstimator, ): r""" Historical functional linear regression. diff --git a/skfda/ml/regression/_kernel_regression.py b/skfda/ml/regression/_kernel_regression.py index db0494dfc..7f634daf1 100644 --- a/skfda/ml/regression/_kernel_regression.py +++ b/skfda/ml/regression/_kernel_regression.py @@ -16,8 +16,8 @@ class KernelRegression( - BaseEstimator, RegressorMixin[Input, Prediction], + BaseEstimator, ): r"""Kernel regression with scalar response. diff --git a/skfda/ml/regression/_linear_regression.py b/skfda/ml/regression/_linear_regression.py index 4cc45524a..5873b37e3 100644 --- a/skfda/ml/regression/_linear_regression.py +++ b/skfda/ml/regression/_linear_regression.py @@ -60,11 +60,11 @@ class LinearRegression( - BaseEstimator, RegressorMixin[ Union[AcceptedDataType, Sequence[AcceptedDataType]], NDArrayFloat, ], + BaseEstimator, ): r"""Linear regression with multivariate and functional response. diff --git a/skfda/preprocessing/dim_reduction/_fpca.py b/skfda/preprocessing/dim_reduction/_fpca.py index 53afcd27d..f12065d7c 100644 --- a/skfda/preprocessing/dim_reduction/_fpca.py +++ b/skfda/preprocessing/dim_reduction/_fpca.py @@ -21,8 +21,8 @@ class FPCA( # noqa: WPS230 (too many public attributes) - BaseEstimator, InductiveTransformerMixin[FData, NDArrayFloat, object], + BaseEstimator, ): r""" Principal component analysis. diff --git a/skfda/preprocessing/dim_reduction/variable_selection/_rkvs.py b/skfda/preprocessing/dim_reduction/variable_selection/_rkvs.py index 925780015..0207b1fb2 100644 --- a/skfda/preprocessing/dim_reduction/variable_selection/_rkvs.py +++ b/skfda/preprocessing/dim_reduction/variable_selection/_rkvs.py @@ -102,8 +102,8 @@ def _rkhs_vs( class RKHSVariableSelection( - BaseEstimator, InductiveTransformerMixin[FDataGrid, NDArrayFloat, NDArrayInt], + BaseEstimator, ): r""" Reproducing kernel variable selection. diff --git a/skfda/preprocessing/dim_reduction/variable_selection/maxima_hunting.py b/skfda/preprocessing/dim_reduction/variable_selection/maxima_hunting.py index 6aa2f9427..7eb59171d 100644 --- a/skfda/preprocessing/dim_reduction/variable_selection/maxima_hunting.py +++ b/skfda/preprocessing/dim_reduction/variable_selection/maxima_hunting.py @@ -109,12 +109,12 @@ def __call__(self, X: FDataGrid) -> NDArrayInt: class MaximaHunting( - BaseEstimator, InductiveTransformerMixin[ FDataGrid, NDArrayFloat, NDArrayReal, ], + BaseEstimator, ): r""" Maxima Hunting variable selection. diff --git a/skfda/preprocessing/dim_reduction/variable_selection/mrmr.py b/skfda/preprocessing/dim_reduction/variable_selection/mrmr.py index 55ad2670a..b8f86a593 100644 --- a/skfda/preprocessing/dim_reduction/variable_selection/mrmr.py +++ b/skfda/preprocessing/dim_reduction/variable_selection/mrmr.py @@ -185,12 +185,12 @@ def _mrmr( class MinimumRedundancyMaximumRelevance( - BaseEstimator, InductiveTransformerMixin[ FDataGrid, NDArrayFloat, Union[NDArrayInt, NDArrayFloat], ], + BaseEstimator, Generic[dtype_y_T], ): r""" diff --git a/skfda/preprocessing/dim_reduction/variable_selection/recursive_maxima_hunting.py b/skfda/preprocessing/dim_reduction/variable_selection/recursive_maxima_hunting.py index ef43ebd46..bb40c657b 100644 --- a/skfda/preprocessing/dim_reduction/variable_selection/recursive_maxima_hunting.py +++ b/skfda/preprocessing/dim_reduction/variable_selection/recursive_maxima_hunting.py @@ -778,12 +778,12 @@ def update_mask( class RecursiveMaximaHunting( - BaseEstimator, InductiveTransformerMixin[ FDataGrid, NDArrayFloat, Union[NDArrayInt, NDArrayFloat], ], + BaseEstimator, ): """ Recursive Maxima Hunting variable selection. diff --git a/skfda/preprocessing/feature_construction/_coefficients_transformer.py b/skfda/preprocessing/feature_construction/_coefficients_transformer.py index 8ac3f6041..672326657 100644 --- a/skfda/preprocessing/feature_construction/_coefficients_transformer.py +++ b/skfda/preprocessing/feature_construction/_coefficients_transformer.py @@ -10,8 +10,8 @@ class CoefficientsTransformer( - BaseEstimator, TransformerMixin[FDataBasis, NDArrayFloat, object], + BaseEstimator, ): r""" Transformer returning the coefficients of FDataBasis objects as a matrix. diff --git a/skfda/preprocessing/feature_construction/_evaluation_trasformer.py b/skfda/preprocessing/feature_construction/_evaluation_trasformer.py index c9382ddde..e00051c4a 100644 --- a/skfda/preprocessing/feature_construction/_evaluation_trasformer.py +++ b/skfda/preprocessing/feature_construction/_evaluation_trasformer.py @@ -21,8 +21,8 @@ class EvaluationTransformer( - BaseEstimator, InductiveTransformerMixin[Input, NDArrayFloat, object], + BaseEstimator, ): r""" Transformer returning the evaluations of FData objects as a matrix. diff --git a/skfda/preprocessing/feature_construction/_function_transformers.py b/skfda/preprocessing/feature_construction/_function_transformers.py index 4e2c1bf30..d5408efea 100644 --- a/skfda/preprocessing/feature_construction/_function_transformers.py +++ b/skfda/preprocessing/feature_construction/_function_transformers.py @@ -14,8 +14,8 @@ class LocalAveragesTransformer( - BaseEstimator, TransformerMixin[FData, NDArrayFloat, object], + BaseEstimator, ): r""" Transforms functional data to its local averages. @@ -102,8 +102,8 @@ def transform(self, X: FData, y: object = None) -> NDArrayFloat: class OccupationMeasureTransformer( - BaseEstimator, TransformerMixin[FData, NDArrayFloat, object], + BaseEstimator, ): """ Transformer that works as an adapter for the occupation_measure function. @@ -175,8 +175,8 @@ def transform(self, X: FData, y: object = None) -> NDArrayFloat: class NumberCrossingsTransformer( - BaseEstimator, TransformerMixin[FDataGrid, NDArrayInt, object], + BaseEstimator, ): """ Transformer that works as an adapter for the number_up_crossings function. diff --git a/skfda/preprocessing/feature_construction/_per_class_transformer.py b/skfda/preprocessing/feature_construction/_per_class_transformer.py index eb8c1fd2d..6b1a309c4 100644 --- a/skfda/preprocessing/feature_construction/_per_class_transformer.py +++ b/skfda/preprocessing/feature_construction/_per_class_transformer.py @@ -10,7 +10,7 @@ from sklearn.utils.validation import check_is_fitted as sklearn_check_is_fitted from ..._utils import _classifier_get_classes -from ..._utils._sklearn_adapter import TransformerMixin +from ..._utils._sklearn_adapter import BaseEstimator, TransformerMixin from ...representation import FData from ...representation.basis import FDataBasis from ...representation.grid import FDataGrid @@ -41,7 +41,10 @@ def _fit_feature_transformer( # noqa: WPS320 WPS234 return classes, class_feature_transformers -class PerClassTransformer(TransformerMixin[Input, Output, NDArrayInt]): +class PerClassTransformer( + TransformerMixin[Input, Output, NDArrayInt], + BaseEstimator, +): r"""Per class feature transformer for functional data. This class takes a transformer and performs the following map: diff --git a/skfda/preprocessing/missing/_interpolate.py b/skfda/preprocessing/missing/_interpolate.py index d97dff0d8..f985ffe6c 100644 --- a/skfda/preprocessing/missing/_interpolate.py +++ b/skfda/preprocessing/missing/_interpolate.py @@ -69,8 +69,8 @@ def _interpolate_nans( class MissingValuesInterpolation( - BaseEstimator, InductiveTransformerMixin[T, T, Any], + BaseEstimator, ): """ Class to interpolate missing values. diff --git a/skfda/preprocessing/registration/_base.py b/skfda/preprocessing/registration/_base.py index 086a7cb08..840c6c84d 100644 --- a/skfda/preprocessing/registration/_base.py +++ b/skfda/preprocessing/registration/_base.py @@ -22,8 +22,8 @@ class RegistrationTransformer( - BaseEstimator, TransformerMixin[Input, Output, object], + BaseEstimator, ): """Base class for the registration methods.""" diff --git a/skfda/preprocessing/smoothing/_linear.py b/skfda/preprocessing/smoothing/_linear.py index 09c6fadcc..5f2b0cc86 100644 --- a/skfda/preprocessing/smoothing/_linear.py +++ b/skfda/preprocessing/smoothing/_linear.py @@ -19,8 +19,8 @@ class _LinearSmoother( - BaseEstimator, TransformerMixin[FDataGrid, FDataGrid, object], + BaseEstimator, ): """Linear smoother. diff --git a/skfda/preprocessing/smoothing/validation.py b/skfda/preprocessing/smoothing/validation.py index 10c628ae8..66ae63c30 100644 --- a/skfda/preprocessing/smoothing/validation.py +++ b/skfda/preprocessing/smoothing/validation.py @@ -141,6 +141,35 @@ def __call__( ) +class _FullSplitter: + """ + Class that serves as a CV splitter for :class:`SmoothingParameterSearch`. + + It returns the full dataset as both train and test set. + This is because the actual CV is performed over the function measurements, + using a fixed formula. + + """ + def split( + self, + X: FDataGrid, + y: FDataGrid | None = None, + groups: NDArrayInt | None = None, + ) -> Iterable[tuple[NDArrayInt, NDArrayInt]]: + """Return the split.""" + idx = np.arange(len(X)) + + return [(idx, idx)] + + def get_n_splits( + self, + X: FDataGrid, + y: FDataGrid | None = None, + groups: NDArrayInt | None = None, + ) -> int: + """Return the number of splits.""" + return 1 + class SmoothingParameterSearch( GridSearchCV, # type: ignore[misc] ): @@ -324,7 +353,7 @@ def __init__( param_grid={param_name: param_values}, n_jobs=n_jobs, refit=True, - cv=[(slice(None), slice(None))], + cv=_FullSplitter(), verbose=verbose, pre_dispatch=pre_dispatch, error_score=error_score,