8000 MNT SLEP6 remove args that shouldn't be included in the routing by adrinjalali · Pull Request #29920 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT SLEP6 remove args that shouldn't be included in the routing #29920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats_new/upcoming_changes/metadata-routing/29920.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Many method arguments which shouldn't be included in the routing mechanism are
now excluded and the `set_{method}_request` methods are not generated for them.
By `Adrin Jalali`_
5 changes: 5 additions & 0 deletions sklearn/covariance/_empirical_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import numpy as np
from scipy import linalg

from sklearn.utils import metadata_routing

from .. import config_context
from ..base import BaseEstimator, _fit_context
from ..metrics.pairwise import pairwise_distances
Expand Down Expand Up @@ -181,6 +183,9 @@ class EmpiricalCovariance(BaseEstimator):
array([0.0622..., 0.0193...])
"""

# X_test should have been called X
__metadata_request__score = {"X_test": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"store_precision": ["boolean"],
"assume_centered": ["boolean"],
Expand Down
4 changes: 4 additions & 0 deletions sklearn/decomposition/_incremental_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import numpy as np
from scipy import linalg, sparse

from sklearn.utils import metadata_routing

from ..base import _fit_context
from ..utils import gen_batches
from ..utils._param_validation import Interval
Expand Down Expand Up @@ -184,6 +186,8 @@ class IncrementalPCA(_BasePCA):
(1797, 7)
"""

__metadata_request__partial_fit = {"check_input": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"n_components": [Interval(Integral, 1, None, closed="left"), None],
"whiten": ["boolean"],
Expand Down
5 changes: 5 additions & 0 deletions sklearn/feature_extraction/_dict_vectorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import numpy as np
import scipy.sparse as sp

from sklearn.utils import metadata_routing

from ..base import BaseEstimator, TransformerMixin, _fit_context
from ..utils import check_array
from ..utils.validation import check_is_fitted
Expand Down Expand Up @@ -91,6 +93,9 @@ class DictVectorizer(TransformerMixin, BaseEstimator):
array([[0., 0., 4.]])
"""

# This isn't something that people should be routing / using in a pipeline.
__metadata_request__inverse_transform = {"dict_type": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"dtype": "no_validation", # validation delegated to numpy,
"separator": [str],
Expand Down
5 changes: 5 additions & 0 deletions sklearn/feature_extraction/_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import numpy as np
import scipy.sparse as sp

from sklearn.utils import metadata_routing

from ..base import BaseEstimator, TransformerMixin, _fit_context
from ..utils._param_validation import Interval, StrOptions
from ._hashing_fast import transform as _hashing_transform
Expand Down Expand Up @@ -104,6 +106,9 @@ class FeatureHasher(TransformerMixin, BaseEstimator):
[ 0., -1., 0., 0., 0., 0., 0., 1.]])
"""

# raw_X should have been called X
__metadata_request__transform = {"raw_X": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"n_features": [Interval(Integral, 1, np.iinfo(np.int32).max, closed="both")],
"input_type": [StrOptions({"dict", "pair", "string"})],
Expand Down
7 changes: 7 additions & 0 deletions sklearn/feature_extraction/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import numpy as np
import scipy.sparse as sp

from sklearn.utils import metadata_routing

from ..base import BaseEstimator, OneToOneFeatureMixin, TransformerMixin, _fit_context
from ..exceptions import NotFittedError
from ..preprocessing import normalize
Expand Down Expand Up @@ -1118,6 +1120,11 @@ class CountVectorizer(_VectorizerMixin, BaseEstimator):
[0 0 1 0 1 0 1 0 0 0 0 0 1]]
"""

# raw_documents should not be in the routing mechanism. It should have been
# called X in the first place.
Comment on lines +1123 to +1124
Copy link
Member
@adam2392 adam2392 Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be handled here, but I wonder does this warrant us renaming this to X to be consistent across the codebase, or low-priority?

Same for the other regions you mentioned.

__metadata_request__fit = {"raw_documents": metadata_routing.UNUSED}
__metadata_request__transform = {"raw_documents": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"input": [StrOptions({"filename", "file", "content"})],
"encoding": [str],
Expand Down
6 changes: 6 additions & 0 deletions sklearn/isotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from scipy import interpolate, optimize
from scipy.stats import spearmanr

from sklearn.utils import metadata_routing

from ._isotonic import _inplace_contiguous_isotonic_regression, _make_unique
from .base import BaseEstimator, RegressorMixin, TransformerMixin, _fit_context
from .utils import check_array, check_consistent_length
Expand Down Expand Up @@ -272,6 +274,10 @@ class IsotonicRegression(RegressorMixin, TransformerMixin, BaseEstimator):
array([1.8628..., 3.7256...])
"""

# T should have been called X
__metadata_request__predict = {"T": metadata_routing.UNUSED}
__metadata_request__transform = {"T": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"y_min": [Interval(Real, None, None, closed="both"), None],
"y_max": [Interval(Real, None, None, closed="both"), None],
Expand Down
6 changes: 6 additions & 0 deletions sklearn/linear_model/_coordinate_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from joblib import effective_n_jobs
from scipy import sparse

from sklearn.utils import metadata_routing

from ..base import MultiOutputMixin, RegressorMixin, _fit_context
from ..model_selection import check_cv
from ..utils import Bunch, check_array, check_scalar
Expand Down Expand Up @@ -875,6 +877,10 @@ class ElasticNet(MultiOutputMixin, RegressorMixin, LinearModel):
[1.451...]
"""

# "check_input" is used for optimisation and isn't something to be passed
# around in a pipeline.
__metadata_request__fit = {"check_input": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"alpha": [Interval(Real, 0, None, closed="left")],
"l1_ratio": [Interval(Real, 0, 1, closed="both")],
Expand Down
6 changes: 6 additions & 0 deletions sklearn/preprocessing/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from scipy import optimize, sparse, stats
from scipy.special import boxcox, inv_boxcox

from sklearn.utils import metadata_routing

from ..base import (
BaseEstimator,
ClassNamePrefixFeaturesOutMixin,
Expand Down Expand Up @@ -2422,6 +2424,10 @@ class KernelCenterer(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEsti
[ -5., -14., 19.]])
"""

# X is called K in these methods.
__metadata_request__transform = {"K": metadata_routing.UNUSED}
__metadata_request__fit = {"K": metadata_routing.UNUSED}

def fit(self, K, y=None):
"""Fit KernelCenterer.

Expand Down
15 changes: 15 additions & 0 deletions sklearn/tree/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import numpy as np
from scipy.sparse import issparse

from sklearn.utils import metadata_routing

from ..base import (
BaseEstimator,
ClassifierMixin,
Expand Down Expand Up @@ -93,6 +95,10 @@ class BaseDecisionTree(MultiOutputMixin, BaseEstimator, metaclass=ABCMeta):
Use derived classes instead.
"""

# "check_input" is used for optimisation and isn't something to be passed
# around in a pipeline.
__metadata_request__predict = {"check_input": metadata_routing.UNUSED}

_parameter_constraints: dict = {
"splitter": [StrOptions({"best", "random"})],
"max_depth": [Interval(Integral, 1, None, closed="left"), None],
Expand Down Expand Up @@ -935,6 +941,11 @@ class DecisionTreeClassifier(ClassifierMixin, BaseDecisionTree):
0.93..., 0.93..., 1. , 0.93..., 1. ])
"""

# "check_input" is used for optimisation and isn't something to be passed
# around in a pipeline.
__metadata_request__predict_proba = {"check_input": metadata_routing.UNUSED}
__metadata_request__fit = {"check_input": metadata_routing.UNUSED}

_parameter_constraints: dict = {
**BaseDecisionTree._parameter_constraints,
"criterion": [StrOptions({"gini", "entropy", "log_loss"}), Hidden(Criterion)],
Expand Down Expand Up @@ -1312,6 +1323,10 @@ class DecisionTreeRegressor(RegressorMixin, BaseDecisionTree):
0.16..., 0.11..., -0.73..., -0.30..., -0.00...])
"""

# "check_input" is used for optimisation and isn't something to be passed
# around in a pipeline.
__metadata_request__fit = {"check_input": metadata_routing.UNUSED}

_parameter_constraints: dict = {
**BaseDecisionTree._parameter_constraints,
"criterion": [
Expand Down
0