Skip to content
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

MNT Deprecate unused parameter from OneClassSVM fit method. #20843

Merged
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
7 changes: 7 additions & 0 deletions doc/whats_new/v1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,13 @@ Changelog
`n_features_in_` and will be removed in 1.2. :pr:`20240` by
:user:`Jérémie du Boisberranger <jeremiedbb>`.

:mod:`sklearn.svm`
...................

- |API| The parameter `**params` of :func:`svm.OneClassSVM.fit` is
deprecated and will be removed in 1.2.
:pr:`20843` by :user:`Juan Martín Loyola <jmloyola>`.

:mod:`sklearn.tree`
...................

Expand Down
17 changes: 16 additions & 1 deletion sklearn/svm/_classes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import warnings

from ._base import _fit_liblinear, BaseSVC, BaseLibSVM
from ..base import BaseEstimator, RegressorMixin, OutlierMixin
Expand Down Expand Up @@ -1604,6 +1605,11 @@ def fit(self, X, y=None, sample_weight=None, **params):
**params : dict
Additional fit parameters.

.. deprecated:: 1.0
The `fit` method will not longer accept extra keyword
parameters in 1.2. These keyword parameters were
already discarded.

Returns
-------
self : object
Expand All @@ -1613,7 +1619,16 @@ def fit(self, X, y=None, sample_weight=None, **params):
-----
If X is not a C-ordered contiguous array it is copied.
"""
super().fit(X, np.ones(_num_samples(X)), sample_weight=sample_weight, **params)
# TODO: Remove in v1.2
if len(params) > 0:
warnings.warn(
"Passing additional keyword parameters has no effect and is "
"deprecated in 1.0. An error will be raised from 1.2 and "
"beyond. The ignored keyword parameter(s) are: "
f"{params.keys()}.",
FutureWarning,
)
super().fit(X, np.ones(_num_samples(X)), sample_weight=sample_weight)
glemaitre marked this conversation as resolved.
Show resolved Hide resolved
self.offset_ = -self._intercept_
return self

Expand Down
17 changes: 17 additions & 0 deletions sklearn/svm/tests/test_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import itertools
import pytest
import re

from numpy.testing import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_almost_equal
Expand Down Expand Up @@ -299,6 +300,22 @@ def test_oneclass_score_samples():
)


# TODO: Remove in v1.2
def test_oneclass_fit_params_is_deprecated():
clf = svm.OneClassSVM()
params = {
"unused_param": "",
"extra_param": None,
}
msg = (
"Passing additional keyword parameters has no effect and is deprecated "
"in 1.0. An error will be raised from 1.2 and beyond. The ignored "
f"keyword parameter(s) are: {params.keys()}."
)
with pytest.warns(FutureWarning, match=re.escape(msg)):
clf.fit(X, **params)


def test_tweak_params():
# Make sure some tweaking of parameters works.
# We change clf.dual_coef_ at run time and expect .predict() to change
Expand Down