8000 MNT Deprecate unused parameter from OneClassSVM fit method. (#20843) · samronsin/scikit-learn@761743f · GitHub
[go: up one dir, main page]

Skip to content

Commit 761743f

Browse files
jmloyolaglemaitre
authored andcommitted
MNT Deprecate unused parameter from OneClassSVM fit method. (scikit-learn#20843)
Co-authored-by: glemaitre <g.lemaitre58@gmail.com>
1 parent 97a2dcf commit 761743f

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

doc/whats_new/v1.0.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,13 @@ Changelog
807807
`n_features_in_` and will be removed in 1.2. :pr:`20240` by
808808
:user:`Jérémie du Boisberranger <jeremiedbb>`.
809809

810+
:mod:`sklearn.svm`
811+
...................
812+
813+
- |API| The parameter `**params` of :func:`svm.OneClassSVM.fit` is
814+
deprecated and will be removed in 1.2.
815+
:pr:`20843` by :user:`Juan Martín Loyola <jmloyola>`.
816+
810817
:mod:`sklearn.tree`
811818
...................
812819

sklearn/svm/_classes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import warnings
23

34
from ._base import _fit_liblinear, BaseSVC, BaseLibSVM
45
from ..base import BaseEstimator, RegressorMixin, OutlierMixin
@@ -1604,6 +1605,11 @@ def fit(self, X, y=None, sample_weight=None, **params):
16041605
**params : dict
16051606
Additional fit parameters.
16061607
1608+
.. deprecated:: 1.0
1609+
The `fit` method will not longer accept extra keyword
1610+
parameters in 1.2. These keyword parameters were
1611+
already discarded.
1612+
16071613
Returns
16081614
-------
16091615
self : object
@@ -1613,7 +1619,16 @@ def fit(self, X, y=None, sample_weight=None, **params):
16131619
-----
16141620
If X is not a C-ordered contiguous array it is copied.
16151621
"""
1616-
super().fit(X, np.ones(_num_samples(X)), sample_weight=sample_weight, **params)
1622+
# TODO: Remove in v1.2
1623+
if len(params) > 0:
1624+
warnings.warn(
1625+
"Passing additional keyword parameters has no effect and is "
1626+
"deprecated in 1.0. An error will be raised from 1.2 and "
1627+
"beyond. The ignored keyword parameter(s) are: "
1628+
f"{params.keys()}.",
1629+
FutureWarning,
1630+
)
1631+
super().fit(X, np.ones(_num_samples(X)), sample_weight=sample_weight)
16171632
self.offset_ = -self._intercept_
16181633
return self
16191634

sklearn/svm/tests/test_svm.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import itertools
88
import pytest
9+
import re
910

1011
from numpy.testing import assert_array_equal, assert_array_almost_equal
1112
from numpy.testing import assert_almost_equal
@@ -299,6 +300,22 @@ def test_oneclass_score_samples():
299300
)
300301

301302

303+
# TODO: Remove in v1.2
304+
def test_oneclass_fit_params_is_deprecated():
305+
clf = svm.OneClassSVM()
306+
params = {
307+
"unused_param": "",
308+
"extra_param": None,
309+
}
310+
msg = (
311+
"Passing additional keyword parameters has no effect and is deprecated "
312+
"in 1.0. An error will be raised from 1.2 and beyond. The ignored "
313+
f"keyword parameter(s) are: {params.keys()}."
314+
)
315+
with pytest.warns(FutureWarning, match=re.escape(msg)):
316+
clf.fit(X, **params)
317+
318+
302319
def test_tweak_params():
303320
# Make sure some tweaking of parameters works.
304321
# We change clf.dual_coef_ at run time and expect .predict() to change

0 commit comments

Comments
 (0)
0