8000 MAINT Clean up deprecations for 1.5: in AdditiveChi2Sampler (#28814) · charlesjhill/scikit-learn@c35a719 · GitHub
[go: up one dir, main page]

Skip to content

Commit c35a719

Browse files
authored
MAINT Clean up deprecations for 1.5: in AdditiveChi2Sampler (scikit-learn#28814)
1 parent f4cc029 commit c35a719

File tree

2 files changed

+23
-71
lines changed

2 files changed

+23
-71
lines changed

sklearn/kernel_approximation.py

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
_fit_context,
2828
)
2929
from .metrics.pairwise import KERNEL_PARAMS, PAIRWISE_KERNEL_FUNCTIONS, pairwise_kernels
30-
from .utils import check_random_state, deprecated
30+
from .utils import check_random_state
3131
from .utils._param_validation import Interval, StrOptions
3232
from .utils.extmath import safe_sparse_dot
3333
from .utils.validation import (
@@ -600,13 +600,6 @@ class AdditiveChi2Sampler(TransformerMixin, BaseEstimator):
600600
601601
Attributes
602602
----------
603-
sample_interval_ : float
604-
Stored sampling interval. Specified as a parameter if `sample_steps`
605-
not in {1,2,3}.
606-
607-
.. deprecated:: 1.3
608-
`sample_interval_` serves internal purposes only and will be removed in 1.5.
609-
610603
n_features_in_ : int
611604
Number of features seen during :term:`fit`.
612605
@@ -693,37 +686,14 @@ def fit(self, X, y=None):
693686
X = self._validate_data(X, accept_sparse="csr")
694687
check_non_negative(X, "X in AdditiveChi2Sampler.fit")
695688

696-
# TODO(1.5): remove the setting of _sample_interval from fit
697-
if self.sample_interval is None:
698-
# See figure 2 c) of "Efficient additive kernels via explicit feature maps"
699-
# <http://www.robots.ox.ac.uk/~vedaldi/assets/pubs/vedaldi11efficient.pdf>
700-
# A. Vedaldi and A. Zisserman, Pattern Analysis and Machine Intelligence,
701-
# 2011
702-
if self.sample_steps == 1:
703-
self._sample_interval = 0.8
704-
elif self.sample_steps == 2:
705-
self._sample_interval = 0.5
706-
elif self.sample_steps == 3:
707-
self._sample_interval = 0.4
708-
else:
709-
raise ValueError(
710-
"If sample_steps is not in [1, 2, 3],"
711-
" you need to provide sample_interval"
712-
)
713-
else:
714-
self._sample_interval = self.sample_interval
689+
if self.sample_interval is None and self.sample_steps not in (1, 2, 3):
690+
raise ValueError(
691+
"If sample_steps is not in [1, 2, 3],"
692+
" you need to provide sample_interval"
693+
)
715694

716695
return self
717696

718-
# TODO(1.5): remove
719-
@deprecated( # type: ignore
720-
"The ``sample_interval_`` attribute was deprecated in version 1.3 and "
721-
"will be removed 1.5."
722-
)
723-
@property
724-
def sample_interval_(self):
725-
return self._sample_interval
726-
727697
def transform(self, X):
728698
"""Apply approximate feature map to X.
729699
@@ -744,29 +714,24 @@ def transform(self, X):
744714
check_non_negative(X, "X in AdditiveChi2Sampler.transform")
745715
sparse = sp.issparse(X)
746716

747-
if hasattr(self, "_sample_interval"):
748-
# TODO(1.5): remove this branch
749-
sample_interval = self._sample_interval
750-
751-
else:
752-
if self.sample_interval is None:
753-
# See figure 2 c) of "Efficient additive kernels via explicit feature maps" # noqa
754-
# <http://www.robots.ox.ac.uk/~vedaldi/assets/pubs/vedaldi11efficient.pdf>
755-
# A. Vedaldi and A. Zisserman, Pattern Analysis and Machine Intelligence, # noqa
756-
# 2011
757-
if self.sample_steps == 1:
758-
sample_interval = 0.8
759-
elif self.sample_steps == 2:
760-
sample_interval = 0.5
761-
elif self.sample_steps == 3:
762-
sample_interval = 0.4
763-
else:
764-
raise ValueError(
765-
"If sample_steps is not in [1, 2, 3],"
766-
" you need to provide sample_interval"
767-
)
717+
if self.sample_interval is None:
718+
# See figure 2 c) of "Efficient additive kernels via explicit feature maps" # noqa
719+
# <http://www.robots.ox.ac.uk/~vedaldi/assets/pubs/vedaldi11efficient.pdf>
720+
# A. Vedaldi and A. Zisserman, Pattern Analysis and Machine Intelligence, # noqa
721+
# 2011
722+
if self.sample_steps == 1:
723+
sample_interval = 0.8
724+
elif self.sample_steps == 2:
725+
sample_interval = 0.5
726+
elif self.sample_steps == 3:
727+
sample_interval = 0.4
768728
else:
769-
sample_interval = self.sample_interval
729+
raise ValueError(
730+
"If sample_steps is not in [1, 2, 3],"
731+
" you need to provide sample_interval"
732+
)
733+
else:
734+
sample_interval = self.sample_interval
770735

771736
# zeroth component
772737
# 1/cosh = sech

sklearn/tests/test_kernel_approximation.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,6 @@ def test_additive_chi2_sampler_sample_steps(method, sample_steps):
144144
assert transformer.sample_interval == sample_interval
145145

146146

147-
# TODO(1.5): remove
148-
def test_additive_chi2_sampler_future_warnings():
149-
"""Check that we raise a FutureWarning when accessing to `sample_interval_`."""
150-
transformer = AdditiveChi2Sampler()
151-
transformer.fit(X)
152-
msg = re.escape(
153-
"The ``sample_interval_`` attribute was deprecated in version 1.3 and "
154-
"will be removed 1.5."
155-
)
156-
with pytest.warns(FutureWarning, match=msg):
157-
assert transformer.sample_interval_ is not None
158-
159-
160147
@pytest.mark.parametrize("method", ["fit", "fit_transform", "transform"])
161148
def test_additive_chi2_sampler_wrong_sample_steps(method):
162149
"""Check that we raise a ValueError on invalid sample_steps"""

0 commit comments

Comments
 (0)
0