Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f316f4c

Browse filesBrowse files
authored
API Deprecates copy_X in TheilSenRegressor (scikit-learn#29105)
1 parent 480e7f3 commit f316f4c
Copy full SHA for f316f4c

File tree

Expand file treeCollapse file tree

3 files changed

+30
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+30
-3
lines changed

‎doc/whats_new/v1.6.rst

Copy file name to clipboardExpand all lines: doc/whats_new/v1.6.rst
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ Changelog
8080
- |Enhancement| Added a function :func:`base.is_clusterer` which determines
8181
whether a given estimator is of category clusterer.
8282
:pr:`28936` by :user:`Christian Veenhuis <ChVeen>`.
83+
84+
:mod:`sklearn.linear_model`
85+
...........................
86+
87+
- |API| Deprecates `copy_X` in :class:`linear_model.TheilSenRegressor` as the parameter
88+
has no effect. `copy_X` will be removed in 1.8.
89+
:pr:`29105` by :user:`Adam Li <adam2392>`.
8390

8491
:mod:`sklearn.metrics`
8592
......................

‎sklearn/linear_model/_theil_sen.py

Copy file name to clipboardExpand all lines: sklearn/linear_model/_theil_sen.py
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ..base import RegressorMixin, _fit_context
2121
from ..exceptions import ConvergenceWarning
2222
from ..utils import check_random_state
23-
from ..utils._param_validation import Interval
23+
from ..utils._param_validation import Hidden, Interval, StrOptions
2424
from ..utils.parallel import Parallel, delayed
2525
from ._base import LinearModel
2626

@@ -228,6 +228,10 @@ class TheilSenRegressor(RegressorMixin, LinearModel):
228228
copy_X : bool, default=True
229229
If True, X will be copied; else, it may be overwritten.
230230
231+
.. deprecated:: 1.6
232+
`copy_X` was deprecated in 1.6 and will be removed in 1.8.
233+
It has no effect as a copy is always made.
234+
231235
max_subpopulation : int, default=1e4
232236
Instead of computing with a set of cardinality 'n choose k', where n is
233237
the number of samples and k is the number of subsamples (at least
@@ -324,7 +328,7 @@ class TheilSenRegressor(RegressorMixin, LinearModel):
324328

325329
_parameter_constraints: dict = {
326330
"fit_intercept": ["boolean"],
327-
"copy_X": ["boolean"],
331+
"copy_X": ["boolean", Hidden(StrOptions({"deprecated"}))],
328332
# target_type should be Integral but can accept Real for backward compatibility
329333
"max_subpopulation": [Interval(Real, 1, None, closed="left")],
330334
"n_subsamples": [None, Integral],
@@ -339,7 +343,7 @@ def __init__(
339343
self,
340344
*,
341345
fit_intercept=True,
342-
copy_X=True,
346+
copy_X="deprecated",
343347
max_subpopulation=1e4,
344348
n_subsamples=None,
345349
max_iter=300,
@@ -411,6 +415,14 @@ def fit(self, X, y):
411415
self : returns an instance of self.
412416
Fitted `TheilSenRegressor` estimator.
413417
"""
418+
if self.copy_X != "deprecated":
419+
warnings.warn(
420+
"`copy_X` was deprecated in 1.6 and will be removed in 1.8 since it "
421+
"has no effect internally. Simply leave this parameter to its default "
422+
"value to avoid this warning.",
423+
FutureWarning,
424+
)
425+
414426
random_state = check_random_state(self.random_state)
415427
X, y = self._validate_data(X, y, y_numeric=True)
416428
n_samples, n_features = X.shape

‎sklearn/linear_model/tests/test_theil_sen.py

Copy file name to clipboardExpand all lines: sklearn/linear_model/tests/test_theil_sen.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,11 @@ def test_less_samples_than_features():
292292
theil_sen = TheilSenRegressor(fit_intercept=True, random_state=0).fit(X, y)
293293
y_pred = theil_sen.predict(X)
294294
assert_array_almost_equal(y_pred, y, 12)
295+
296+
297+
# TODO(1.8): Remove
298+
def test_copy_X_deprecated():
299+
X, y, _, _ = gen_toy_problem_1d()
300+
theil_sen = TheilSenRegressor(copy_X=True, random_state=0)
301+
with pytest.warns(FutureWarning, match="`copy_X` was deprecated"):
302+
theil_sen.fit(X, y)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.