From 844db02de847cf97ad571485cb39bcba96371c11 Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Thu, 28 Sep 2023 14:19:40 +0200 Subject: [PATCH 01/12] routing for SelectFromModel --- sklearn/feature_selection/_from_model.py | 91 ++++++++++++++++--- .../test_metaestimators_metadata_routing.py | 9 +- 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index dadca96d5df5f..f766dcfdabd3f 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -11,8 +11,10 @@ from ..utils._param_validation import HasMethods, Interval, Options from ..utils._tags import _safe_tags from ..utils.metadata_routing import ( - _raise_for_unsupported_routing, - _RoutingNotSupportedMixin, + MetadataRouter, + MethodMapping, + _routing_enabled, + process_routing, ) from ..utils.metaestimators import available_if from ..utils.validation import _num_features, check_is_fitted, check_scalar @@ -82,9 +84,7 @@ def _estimator_has(attr): ) -class SelectFromModel( - _RoutingNotSupportedMixin, MetaEstimatorMixin, SelectorMixin, BaseEstimator -): +class SelectFromModel(MetaEstimatorMixin, SelectorMixin, BaseEstimator): """Meta-transformer for selecting features based on importance weights. .. versionadded:: 0.17 @@ -341,14 +341,29 @@ def fit(self, X, y=None, **fit_params): classification, real numbers in regression). **fit_params : dict - Other estimator specific parameters. + - If `enable_metadata_routing=False` (default): + + Other estimator specific parameters. + + - If `enable_metadata_routing=True`: + + Parameters passed to the ``estimator.fit`` method of each + sub-estimator. They are ignored if prefit=True or if estimator + is already fitted. + + .. versionchanged:: 1.4 + **fit_params are routed via the common metadata routing + utilities, if `enable_metadata_routing=True` is set via + :func:`~sklearn.set_config`. + + See :ref:`Metadata Routing User Guide ` for more + details. Returns ------- self : object Fitted estimator. """ - _raise_for_unsupported_routing(self, "fit", **fit_params) self._check_max_features(X) if self.prefit: @@ -361,8 +376,14 @@ def fit(self, X, y=None, **fit_params): ) from exc self.estimator_ = deepcopy(self.estimator) else: - self.estimator_ = clone(self.estimator) - self.estimator_.fit(X, y, **fit_params) + if _routing_enabled(): + routed_params = process_routing(self, "fit", **fit_params) + self.estimator_ = clone(self.estimator) + self.estimator_.fit(X, y, **routed_params.estimator.fit) + else: + # TODO(SLEP6): remove when metadata routing cannot be disabled. + self.estimator_ = clone(self.estimator) + self.estimator_.fit(X, y, **fit_params) if hasattr(self.estimator_, "feature_names_in_"): self.feature_names_in_ = self.estimator_.feature_names_in_ @@ -387,7 +408,7 @@ def threshold_(self): # SelectFromModel.estimator is not validated yet prefer_skip_nested_validation=False ) - def partial_fit(self, X, y=None, **fit_params): + def partial_fit(self, X, y=None, **params): """Fit the SelectFromModel meta-transformer only once. Parameters @@ -399,8 +420,24 @@ def partial_fit(self, X, y=None, **fit_params): The target values (integers that correspond to classes in classification, real numbers in regression). - **fit_params : dict - Other estimator specific parameters. + **params : dict + - If `enable_metadata_routing=False` (default): + + Other estimator specific parameters. + + - If `enable_metadata_routing=True`: + + Parameters passed to the ``estimator.fit`` method of each + sub-estimator. They are ignored if prefit=True or if estimator + is already fitted. + + .. versionchanged:: 1.4 + **params are routed via the common metadata routing + utilities, if `enable_metadata_routing=True` is set via + :func:`~sklearn.set_config`. + + See :ref:`Metadata Routing User Guide ` for more + details. Returns ------- @@ -426,7 +463,13 @@ def partial_fit(self, X, y=None, **fit_params): if first_call: self.estimator_ = clone(self.estimator) - self.estimator_.partial_fit(X, y, **fit_params) + if _routing_enabled(): + routed_params = process_routing(self, "partial_fit", **params) + self.estimator_ = clone(self.estimator) + self.estimator_.partial_fit(X, y, **routed_params.estimator.partial_fit) + else: + # TODO(SLEP6): remove when metadata routing cannot be disabled. + self.estimator_.partial_fit(X, y, **params) if hasattr(self.estimator_, "feature_names_in_"): self.feature_names_in_ = self.estimator_.feature_names_in_ @@ -451,5 +494,27 @@ def n_features_in_(self): return self.estimator_.n_features_in_ + def get_metadata_routing(self): + """Get metadata routing of this object. + + Please check :ref:`User Guide ` on how the routing + mechanism works. + + .. versionadded:: 1.3 + + Returns + ------- + routing : MetadataRouter + A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating + routing information. + """ + router = MetadataRouter(owner=self.__class__.__name__).add( + estimator=self.estimator, + method_mapping=MethodMapping() + .add(callee="partial_fit", caller="partial_fit") + .add(callee="fit", caller="fit"), + ) + return router + def _more_tags(self): return {"allow_nan": _safe_tags(self.estimator, key="allow_nan")} diff --git a/sklearn/tests/test_metaestimators_metadata_routing.py b/sklearn/tests/test_metaestimators_metadata_routing.py index 7956ed5f3726e..1d70f9df25f52 100644 --- a/sklearn/tests/test_metaestimators_metadata_routing.py +++ b/sklearn/tests/test_metaestimators_metadata_routing.py @@ -197,6 +197,14 @@ def enable_slep006(): "cv_name": "cv", "cv_routing_methods": ["fit"], }, + { + "metaestimator": SelectFromModel, + "estimator_name": "estimator", + "estimator": ConsumingClassifier, + "X": X, + "y": y, + "estimator_routing_methods": ["fit", "partial_fit"], + }, ] """List containing all metaestimators to be tested and their settings @@ -253,7 +261,6 @@ def enable_slep006(): RFECV(ConsumingClassifier()), RidgeCV(), RidgeClassifierCV(), - SelectFromModel(ConsumingClassifier()), SelfTrainingClassifier(ConsumingClassifier()), SequentialFeatureSelector(ConsumingClassifier()), StackingClassifier(ConsumingClassifier()), From 3238b6c47e66c69ed62be1e559389b012805e912 Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Thu, 28 Sep 2023 14:27:28 +0200 Subject: [PATCH 02/12] changelog added --- doc/whats_new/v1.4.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/whats_new/v1.4.rst b/doc/whats_new/v1.4.rst index d4f92548ba0ac..bfd8d41eb9541 100644 --- a/doc/whats_new/v1.4.rst +++ b/doc/whats_new/v1.4.rst @@ -73,6 +73,10 @@ more details. ``**score_params`` which are passed to the underlying scorer. :pr:`26525` by :user:`Omar Salman `. +- |Feature| :class:`feature_selection.SelectFromModel` now supports metadata + routing according to :ref:`metadata routing user guide `. + :pr:`27490` by :user:`Stefanie Senger `. + - |Fix| All meta-estimators for which metadata routing is not yet implemented now raise a `NotImplementedError` on `get_metadata_routing` and on `fit` if metadata routing is enabled and any metadata is passed to them. :pr:`27389` From aa902ace7e43b5194962f163645b480aba5c8f19 Mon Sep 17 00:00:00 2001 From: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:33:25 +0200 Subject: [PATCH 03/12] Update sklearn/feature_selection/_from_model.py Co-authored-by: Adrin Jalali --- sklearn/feature_selection/_from_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index f766dcfdabd3f..e7e4ab171b3ee 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -343,7 +343,7 @@ def fit(self, X, y=None, **fit_params): **fit_params : dict - If `enable_metadata_routing=False` (default): - Other estimator specific parameters. + These arguments will be directly passed to the sub-estimator. - If `enable_metadata_routing=True`: From e88e0bd45fc9dc593612cc45f7c1251f5d119b4c Mon Sep 17 00:00:00 2001 From: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:42:02 +0200 Subject: [PATCH 04/12] Update sklearn/feature_selection/_from_model.py Co-authored-by: Adrin Jalali --- sklearn/feature_selection/_from_model.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index e7e4ab171b3ee..db2c0311be7ae 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -347,9 +347,8 @@ def fit(self, X, y=None, **fit_params): - If `enable_metadata_routing=True`: - Parameters passed to the ``estimator.fit`` method of each - sub-estimator. They are ignored if prefit=True or if estimator - is already fitted. + Parameters passed to the ``estimator.fit`` method of the + sub-estimator. They are ignored if `prefit=True`. .. versionchanged:: 1.4 **fit_params are routed via the common metadata routing From 7c122fec065900d2a9fc515b137843e7e13fdd1e Mon Sep 17 00:00:00 2001 From: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:50:30 +0200 Subject: [PATCH 05/12] Update doc/whats_new/v1.4.rst Co-authored-by: Adrin Jalali --- doc/whats_new/v1.4.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats_new/v1.4.rst b/doc/whats_new/v1.4.rst index bfd8d41eb9541..3360ccf304c17 100644 --- a/doc/whats_new/v1.4.rst +++ b/doc/whats_new/v1.4.rst @@ -74,7 +74,7 @@ more details. :pr:`26525` by :user:`Omar Salman `. - |Feature| :class:`feature_selection.SelectFromModel` now supports metadata - routing according to :ref:`metadata routing user guide `. + routing in `fit` and `partial_fit`. :pr:`27490` by :user:`Stefanie Senger `. - |Fix| All meta-estimators for which metadata routing is not yet implemented From bf0bd383cbe3e03a8003185f44a071c7f6bb3ceb Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Fri, 29 Sep 2023 11:43:16 +0200 Subject: [PATCH 06/12] changes after review --- doc/metadata_routing.rst | 2 +- sklearn/feature_selection/_from_model.py | 37 ++++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/metadata_routing.rst b/doc/metadata_routing.rst index 61fc7a8f72b65..c92b0ef0c0c71 100644 --- a/doc/metadata_routing.rst +++ b/doc/metadata_routing.rst @@ -252,6 +252,7 @@ Meta-estimators and functions supporting metadata routing: - :class:`sklearn.calibration.CalibratedClassifierCV` - :class:`sklearn.compose.ColumnTransformer` +- :class:`sklearn.feature_selection.SelectFromModel` - :class:`sklearn.linear_model.LogisticRegressionCV` - :class:`sklearn.model_selection.GridSearchCV` - :class:`sklearn.model_selection.HalvingGridSearchCV` @@ -280,7 +281,6 @@ Meta-estimators and tools not supporting metadata routing yet: - :class:`sklearn.ensemble.VotingRegressor` - :class:`sklearn.feature_selection.RFE` - :class:`sklearn.feature_selection.RFECV` -- :class:`sklearn.feature_selection.SelectFromModel` - :class:`sklearn.feature_selection.SequentialFeatureSelector` - :class:`sklearn.impute.IterativeImputer` - :class:`sklearn.linear_model.ElasticNetCV` diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index db2c0311be7ae..6624bff0c734d 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -343,20 +343,21 @@ def fit(self, X, y=None, **fit_params): **fit_params : dict - If `enable_metadata_routing=False` (default): - These arguments will be directly passed to the sub-estimator. + Parameters directly passed to the ``fit`` method of the + sub-estimator. - If `enable_metadata_routing=True`: - Parameters passed to the ``estimator.fit`` method of the - sub-estimator. They are ignored if `prefit=True`. + Parameters passed to the ``fit`` method of the sub-estimator. + They are ignored if `prefit=True`. .. versionchanged:: 1.4 - **fit_params are routed via the common metadata routing - utilities, if `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config`. + **fit_params are routed to the sub-estimator used , if + `enable_metadata_routing=True` is set via + :func:`~sklearn.set_config`, which allows for aliasing. - See :ref:`Metadata Routing User Guide ` for more - details. + See :ref:`Metadata Routing User Guide ` for + more details. Returns ------- @@ -422,21 +423,21 @@ def partial_fit(self, X, y=None, **params): **params : dict - If `enable_metadata_routing=False` (default): - Other estimator specific parameters. + Parameters directly passed to the ``partial_fit`` method of the + sub-estimator. - If `enable_metadata_routing=True`: - Parameters passed to the ``estimator.fit`` method of each - sub-estimator. They are ignored if prefit=True or if estimator - is already fitted. + Parameters passed to the ``partial_fit`` method of the + sub-estimator. They are ignored if prefit=True. .. versionchanged:: 1.4 - **params are routed via the common metadata routing - utilities, if `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config`. + **params are routed to the sub-estimator, if + `enable_metadata_routing=True` is set via + :func:`~sklearn.set_config`, which allows for aliasing. - See :ref:`Metadata Routing User Guide ` for more - details. + See :ref:`Metadata Routing User Guide ` for + more details. Returns ------- @@ -499,7 +500,7 @@ def get_metadata_routing(self): Please check :ref:`User Guide ` on how the routing mechanism works. - .. versionadded:: 1.3 + .. versionadded:: 1.4 Returns ------- From 776f44889170399ba86163ad1d7af751a0e48bc3 Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Fri, 29 Sep 2023 13:34:11 +0200 Subject: [PATCH 07/12] backticks to come by sphinx error --- sklearn/feature_selection/_from_model.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index 6624bff0c734d..77cd01afe7858 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -343,16 +343,16 @@ def fit(self, X, y=None, **fit_params): **fit_params : dict - If `enable_metadata_routing=False` (default): - Parameters directly passed to the ``fit`` method of the + Parameters directly passed to the `fit` method of the sub-estimator. - If `enable_metadata_routing=True`: - Parameters passed to the ``fit`` method of the sub-estimator. + Parameters passed to the `fit` method of the sub-estimator. They are ignored if `prefit=True`. .. versionchanged:: 1.4 - **fit_params are routed to the sub-estimator used , if + `**fit_params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via :func:`~sklearn.set_config`, which allows for aliasing. @@ -423,16 +423,16 @@ def partial_fit(self, X, y=None, **params): **params : dict - If `enable_metadata_routing=False` (default): - Parameters directly passed to the ``partial_fit`` method of the + Parameters directly passed to the `partial_fit` method of the sub-estimator. - If `enable_metadata_routing=True`: - Parameters passed to the ``partial_fit`` method of the - sub-estimator. They are ignored if prefit=True. + Parameters passed to the `partial_fit` method of the + sub-estimator. They are ignored if `prefit=True`. .. versionchanged:: 1.4 - **params are routed to the sub-estimator, if + `**params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via :func:`~sklearn.set_config`, which allows for aliasing. From 3a74974c30248981e5f990e638ce3322e69b757a Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Thu, 5 Oct 2023 14:15:52 +0200 Subject: [PATCH 08/12] added config_context and partial_fit always set_fit_request classes --- sklearn/feature_selection/_from_model.py | 6 ++++-- sklearn/tests/test_metaestimators_metadata_routing.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index 77cd01afe7858..3d5dda07757a7 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -354,7 +354,8 @@ def fit(self, X, y=None, **fit_params): .. versionchanged:: 1.4 `**fit_params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config`, which allows for aliasing. + :func:`~sklearn.set_config` or via + :func:`~sklearn.config_context`, which allows for aliasing. See :ref:`Metadata Routing User Guide ` for more details. @@ -434,7 +435,8 @@ def partial_fit(self, X, y=None, **params): .. versionchanged:: 1.4 `**params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config`, which allows for aliasing. + :func:`~sklearn.set_config` or via + :func:`~sklearn.config_context`, which allows for aliasing. See :ref:`Metadata Routing User Guide ` for more details. diff --git a/sklearn/tests/test_metaestimators_metadata_routing.py b/sklearn/tests/test_metaestimators_metadata_routing.py index cc79c73ba6a31..6f43cdec45095 100644 --- a/sklearn/tests/test_metaestimators_metadata_routing.py +++ b/sklearn/tests/test_metaestimators_metadata_routing.py @@ -5,6 +5,7 @@ import pytest from sklearn import config_context +from sklearn.base import is_classifier from sklearn.calibration import CalibratedClassifierCV from sklearn.compose import TransformedTargetRegressor from sklearn.covariance import GraphicalLassoCV @@ -235,6 +236,7 @@ def enable_slep006(): "X": X, "y": y, "estimator_routing_methods": ["fit", "partial_fit"], + "method_args": {"partial_fit": {"classes": classes}}, }, ] """List containing all metaestimators to be tested and their settings @@ -442,6 +444,8 @@ def set_request(estimator, method_name): # e.g. call set_fit_request on estimator set_request_for_method = getattr(estimator, f"set_{method_name}_request") set_request_for_method(sample_weight=True, metadata=True) + if is_classifier(estimator) and method_name == "partial_fit": + set_request_for_method(classes=True) cls = metaestimator["metaestimator"] X = metaestimator["X"] From 8a5de31810c059f5de500199a66fcf9c59bb69a3 Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Thu, 5 Oct 2023 14:21:01 +0200 Subject: [PATCH 09/12] renamed partial_fit_params --- sklearn/feature_selection/_from_model.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index 3d5dda07757a7..7e5af4e3c73fc 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -409,7 +409,7 @@ def threshold_(self): # SelectFromModel.estimator is not validated yet prefer_skip_nested_validation=False ) - def partial_fit(self, X, y=None, **params): + def partial_fit(self, X, y=None, **partial_fit_params): """Fit the SelectFromModel meta-transformer only once. Parameters @@ -421,7 +421,7 @@ def partial_fit(self, X, y=None, **params): The target values (integers that correspond to classes in classification, real numbers in regression). - **params : dict + **partial_fit_params : dict - If `enable_metadata_routing=False` (default): Parameters directly passed to the `partial_fit` method of the @@ -433,7 +433,7 @@ def partial_fit(self, X, y=None, **params): sub-estimator. They are ignored if `prefit=True`. .. versionchanged:: 1.4 - `**params` are routed to the sub-estimator, if + `**partial_fit_params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via :func:`~sklearn.set_config` or via :func:`~sklearn.config_context`, which allows for aliasing. @@ -466,12 +466,12 @@ def partial_fit(self, X, y=None, **params): if first_call: self.estimator_ = clone(self.estimator) if _routing_enabled(): - routed_params = process_routing(self, "partial_fit", **params) + routed_params = process_routing(self, "partial_fit", **partial_fit_params) self.estimator_ = clone(self.estimator) self.estimator_.partial_fit(X, y, **routed_params.estimator.partial_fit) else: # TODO(SLEP6): remove when metadata routing cannot be disabled. - self.estimator_.partial_fit(X, y, **params) + self.estimator_.partial_fit(X, y, **partial_fit_params) if hasattr(self.estimator_, "feature_names_in_"): self.feature_names_in_ = self.estimator_.feature_names_in_ From bc75dfe3663320b022438f201b32ca4962172fb9 Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Fri, 6 Oct 2023 12:06:26 +0200 Subject: [PATCH 10/12] without config_context --- sklearn/feature_selection/_from_model.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index 7e5af4e3c73fc..0306286a02831 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -354,8 +354,7 @@ def fit(self, X, y=None, **fit_params): .. versionchanged:: 1.4 `**fit_params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config` or via - :func:`~sklearn.config_context`, which allows for aliasing. + :func:`~sklearn.set_config`, which allows for aliasing. See :ref:`Metadata Routing User Guide ` for more details. @@ -435,8 +434,7 @@ def partial_fit(self, X, y=None, **partial_fit_params): .. versionchanged:: 1.4 `**partial_fit_params` are routed to the sub-estimator, if `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config` or via - :func:`~sklearn.config_context`, which allows for aliasing. + :func:`~sklearn.set_config`, which allows for aliasing. See :ref:`Metadata Routing User Guide ` for more details. From 969ef28814b309f0c3b48ca1b5616ebdd8500541 Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Fri, 13 Oct 2023 09:53:36 +0200 Subject: [PATCH 11/12] docstring --- sklearn/feature_selection/_from_model.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index 0306286a02831..79a8f3e163d86 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -340,24 +340,20 @@ def fit(self, X, y=None, **fit_params): The target values (integers that correspond to classes in classification, real numbers in regression). - **fit_params : dict + **partial_fit_params : dict - If `enable_metadata_routing=False` (default): - Parameters directly passed to the `fit` method of the - sub-estimator. + Parameters directly passed to the `partial_fit` method of the + sub-estimator. They are ignored if `prefit=True`. - If `enable_metadata_routing=True`: - Parameters passed to the `fit` method of the sub-estimator. - They are ignored if `prefit=True`. + Parameters safely routed to the `partial_fit` method of the + sub-estimator. They are ignored if `prefit=True`. .. versionchanged:: 1.4 - `**fit_params` are routed to the sub-estimator, if - `enable_metadata_routing=True` is set via - :func:`~sklearn.set_config`, which allows for aliasing. - - See :ref:`Metadata Routing User Guide ` for - more details. + See :ref:`Metadata Routing User Guide ` for + more details. Returns ------- From 8724ad3730e804ff590750e55f0b6fcbdd26eb0e Mon Sep 17 00:00:00 2001 From: Stefanie Senger Date: Fri, 27 Oct 2023 22:20:06 +0200 Subject: [PATCH 12/12] correct docstring --- sklearn/feature_selection/_from_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/feature_selection/_from_model.py b/sklearn/feature_selection/_from_model.py index e7124ff00c6db..45785cf29fce7 100644 --- a/sklearn/feature_selection/_from_model.py +++ b/sklearn/feature_selection/_from_model.py @@ -340,7 +340,7 @@ def fit(self, X, y=None, **fit_params): The target values (integers that correspond to classes in classification, real numbers in regression). - **partial_fit_params : dict + **fit_params : dict - If `enable_metadata_routing=False` (default): Parameters directly passed to the `partial_fit` method of the