Skip to content

Commit 03078d5

Browse files
authored
MAINT remove deprecated params for 0.13 (#1112)
1 parent ffa98a3 commit 03078d5

19 files changed

+666
-1015
lines changed

imblearn/combine/_smote_enn.py

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def _validate_estimator(self):
141141
self.smote_ = SMOTE(
142142
sampling_strategy=self.sampling_strategy,
143143
random_state=self.random_state,
144-
n_jobs=self.n_jobs,
145144
)
146145

147146
if self.enn is not None:

imblearn/combine/_smote_tomek.py

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def _validate_estimator(self):
140140
self.smote_ = SMOTE(
141141
sampling_strategy=self.sampling_strategy,
142142
random_state=self.random_state,
143-
n_jobs=self.n_jobs,
144143
)
145144

146145
if self.tomek is not None:

imblearn/combine/tests/test_smote_enn.py

-2
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,10 @@ def test_parallelisation():
146146
smt = SMOTEENN(random_state=RND_SEED)
147147
smt._validate_estimator()
148148
assert smt.n_jobs is None
149-
assert smt.smote_.n_jobs is None
150149
assert smt.enn_.n_jobs is None
151150

152151
# Check if job count is set
153152
smt = SMOTEENN(random_state=RND_SEED, n_jobs=8)
154153
smt._validate_estimator()
155154
assert smt.n_jobs == 8
156-
assert smt.smote_.n_jobs == 8
157155
assert smt.enn_.n_jobs == 8

imblearn/combine/tests/test_smote_tomek.py

-2
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,10 @@ def test_parallelisation():
156156
smt = SMOTETomek(random_state=RND_SEED)
157157
smt._validate_estimator()
158158
assert smt.n_jobs is None
159-
assert smt.smote_.n_jobs is None
160159
assert smt.tomek_.n_jobs is None
161160

162161
# Check if job count is set
163162
smt = SMOTETomek(random_state=RND_SEED, n_jobs=8)
164163
smt._validate_estimator()
165164
assert smt.n_jobs == 8
166-
assert smt.smote_.n_jobs == 8
167165
assert smt.tomek_.n_jobs == 8

imblearn/ensemble/_bagging.py

+2-55
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,17 @@
1010
import numpy as np
1111
from sklearn.base import clone
1212
from sklearn.ensemble import BaggingClassifier
13-
from sklearn.ensemble._bagging import _parallel_decision_function
14-
from sklearn.ensemble._base import _partition_estimators
1513
from sklearn.tree import DecisionTreeClassifier
1614
from sklearn.utils._param_validation import HasMethods, Interval, StrOptions
1715
from sklearn.utils.fixes import parse_version
18-
from sklearn.utils.metaestimators import available_if
19-
from sklearn.utils.parallel import Parallel, delayed
20-
from sklearn.utils.validation import check_is_fitted
2116

2217
from ..pipeline import Pipeline
2318
from ..under_sampling import RandomUnderSampler
2419
from ..under_sampling.base import BaseUnderSampler
2520
from ..utils import Substitution, check_sampling_strategy, check_target_type
2621
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
27-
from ..utils._sklearn_compat import _fit_context, sklearn_version, validate_data
28-
from ._common import _bagging_parameter_constraints, _estimator_has
22+
from ..utils._sklearn_compat import _fit_context, sklearn_version
23+
from ._common import _bagging_parameter_constraints
2924

3025

3126
@Substitution(
@@ -356,54 +351,6 @@ def _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None):
356351
# None.
357352
return super()._fit(X, y, self.max_samples)
358353

359-
# TODO: remove when minimum supported version of scikit-learn is 1.1
360-
@available_if(_estimator_has("decision_function"))
361-
def decision_function(self, X):
362-
"""Average of the decision functions of the base classifiers.
363-
364-
Parameters
365-
----------
366-
X : {array-like, sparse matrix} of shape (n_samples, n_features)
367-
The training input samples. Sparse matrices are accepted only if
368-
they are supported by the base estimator.
369-
370-
Returns
371-
-------
372-
score : ndarray of shape (n_samples, k)
373-
The decision function of the input samples. The columns correspond
374-
to the classes in sorted order, as they appear in the attribute
375-
``classes_``. Regression and binary classification are special
376-
cases with ``k == 1``, otherwise ``k==n_classes``.
377-
"""
378-
check_is_fitted(self)
379-
380-
# Check data
381-
X = validate_data(
382-
self,
383-
X=X,
384-
accept_sparse=["csr", "csc"],
385-
dtype=None,
386-
ensure_all_finite=False,
387-
reset=False,
388-
)
389-
390-
# Parallel loop
391-
n_jobs, _, starts = _partition_estimators(self.n_estimators, self.n_jobs)
392-
393-
all_decisions = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
394-
delayed(_parallel_decision_function)(
395-
self.estimators_[starts[i] : starts[i + 1]],
396-
self.estimators_features_[starts[i] : starts[i + 1]],
397-
X,
398-
)
399-
for i in range(n_jobs)
400-
)
401-
402-
# Reduce
403-
decisions = sum(all_decisions) / self.n_estimators
404-
405-
return decisions
406-
407354
@property
408355
def base_estimator_(self):
409356
"""Attribute for older sklearn version compatibility."""

imblearn/ensemble/_easy_ensemble.py

-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import copy
88
import numbers
9-
import warnings
109

1110
import numpy as np
1211
from sklearn.base import clone
@@ -248,20 +247,6 @@ def _validate_estimator(self, default=AdaBoostClassifier(algorithm="SAMME")):
248247
)
249248
self.estimator_ = Pipeline([("sampler", sampler), ("classifier", estimator)])
250249

251-
# TODO: remove when supporting scikit-learn>=1.2
252-
@property
253-
def n_features_(self):
254-
"""Number of features when ``fit`` is performed."""
255-
warnings.warn(
256-
(
257-
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
258-
"not be accessible when the minimum supported version of scikit-learn "
259-
"is 1.2."
260-
),
261-
FutureWarning,
262-
)
263-
return self.n_features_in_
264-
265250
@_fit_context(prefer_skip_nested_validation=False)
266251
def fit(self, X, y):
267252
"""Build a Bagging ensemble of estimators from the training set (X, y).

imblearn/ensemble/_forest.py

+8-51
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,10 @@ def __init__(
437437
max_features="sqrt",
438438
max_leaf_nodes=None,
439439
min_impurity_decrease=0.0,
440-
bootstrap="warn",
440+
bootstrap=False,
441441
oob_score=False,
442-
sampling_strategy="warn",
443-
replacement="warn",
442+
sampling_strategy="all",
443+
replacement=True,
444444
n_jobs=None,
445445
random_state=None,
446446
verbose=0,
@@ -498,7 +498,7 @@ def _validate_estimator(self, default=DecisionTreeClassifier()):
498498

499499
self.base_sampler_ = RandomUnderSampler(
500500
sampling_strategy=self._sampling_strategy,
501-
replacement=self._replacement,
501+
replacement=self.replacement,
502502
)
503503

504504
def _make_sampler_estimator(self, random_state=None):
@@ -544,49 +544,6 @@ def fit(self, X, y, sample_weight=None):
544544
The fitted instance.
545545
"""
546546
self._validate_params()
547-
# TODO: remove in 0.13
548-
if self.sampling_strategy == "warn":
549-
warn(
550-
(
551-
"The default of `sampling_strategy` will change from `'auto'` to"
552-
" `'all'` in version 0.13. This change will follow the"
553-
" implementation proposed in the original paper. Set to `'all'` to"
554-
" silence this warning and adopt the future behaviour."
555-
),
556-
FutureWarning,
557-
)
558-
self._sampling_strategy = "auto"
559-
else:
560-
self._sampling_strategy = self.sampling_strategy
561-
562-
if self.replacement == "warn":
563-
warn(
564-
(
565-
"The default of `replacement` will change from `False` to `True` in"
566-
" version 0.13. This change will follow the implementation proposed"
567-
" in the original paper. Set to `True` to silence this warning and"
568-
" adopt the future behaviour."
569-
),
570-
FutureWarning,
571-
)
572-
self._replacement = False
573-
else:
574-
self._replacement = self.replacement
575-
576-
if self.bootstrap == "warn":
577-
warn(
578-
(
579-
"The default of `bootstrap` will change from `True` to `False` in"
580-
" version 0.13. This change will follow the implementation proposed"
581-
" in the original paper. Set to `False` to silence this warning and"
582-
" adopt the future behaviour."
583-
),
584-
FutureWarning,
585-
)
586-
self._bootstrap = True
587-
else:
588-
self._bootstrap = self.bootstrap
589-
590547
# Validate or convert input data
591548
if issparse(y):
592549
raise ValueError("sparse multilabel-indicator for y is not supported.")
@@ -657,7 +614,7 @@ def fit(self, X, y, sample_weight=None):
657614
if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
658615
y_encoded = np.ascontiguousarray(y_encoded, dtype=DOUBLE)
659616

660-
if isinstance(self._sampling_strategy, dict):
617+
if isinstance(self.sampling_strategy, dict):
661618
self._sampling_strategy = {
662619
np.where(self.classes_[0] == key)[0][0]: value
663620
for key, value in check_sampling_strategy(
@@ -667,7 +624,7 @@ def fit(self, X, y, sample_weight=None):
667624
).items()
668625
}
669626
else:
670-
self._sampling_strategy = self._sampling_strategy
627+
self._sampling_strategy = self.sampling_strategy
671628

672629
if expanded_class_weight is not None:
673630
if sample_weight is not None:
@@ -683,7 +640,7 @@ def fit(self, X, y, sample_weight=None):
683640
# Check parameters
684641
self._validate_estimator()
685642

686-
if not self._bootstrap and self.oob_score:
643+
if not self.bootstrap and self.oob_score:
687644
raise ValueError("Out of bag estimation only available if bootstrap=True")
688645

689646
random_state = check_random_state(self.random_state)
@@ -735,7 +692,7 @@ def fit(self, X, y, sample_weight=None):
735692
delayed(_local_parallel_build_trees)(
736693
s,
737694
t,
738-
self._bootstrap,
695+
self.bootstrap,
739696
X,
740697
y_encoded,
741698
sample_weight,

imblearn/ensemble/tests/test_forest.py

-18
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,6 @@ def test_balanced_random_forest_oob_binomial(ratio):
217217
assert np.abs(erf.oob_score_ - 0.5) < 0.1
218218

219219

220-
# TODO: remove in 0.13
221-
def test_balanced_random_forest_change_behaviour(imbalanced_dataset):
222-
"""Check that we raise a change of behaviour for the parameters `sampling_strategy`
223-
and `replacement`.
224-
"""
225-
estimator = BalancedRandomForestClassifier(sampling_strategy="all", bootstrap=False)
226-
with pytest.warns(FutureWarning, match="The default of `replacement`"):
227-
estimator.fit(*imbalanced_dataset)
228-
estimator = BalancedRandomForestClassifier(replacement=True, bootstrap=False)
229-
with pytest.warns(FutureWarning, match="The default of `sampling_strategy`"):
230-
estimator.fit(*imbalanced_dataset)
231-
estimator = BalancedRandomForestClassifier(
232-
sampling_strategy="all", replacement=True
233-
)
234-
with pytest.warns(FutureWarning, match="The default of `bootstrap`"):
235-
estimator.fit(*imbalanced_dataset)
236-
237-
238220
@pytest.mark.skipif(
239221
parse_version(sklearn_version.base_version) < parse_version("1.4"),
240222
reason="scikit-learn should be >= 1.4",

imblearn/over_sampling/_adasyn.py

+1-25
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
# License: MIT
66

77
import numbers
8-
import warnings
98

109
import numpy as np
1110
from scipy import sparse
1211
from sklearn.utils import _safe_indexing, check_random_state
1312
from sklearn.utils._param_validation import HasMethods, Interval
1413

1514
from ..utils import Substitution, check_neighbors_object
16-
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
15+
from ..utils._docstring import _random_state_docstring
1716
from .base import BaseOverSampler
1817

1918

2019
@Substitution(
2120
sampling_strategy=BaseOverSampler._sampling_strategy_docstring,
22-
n_jobs=_n_jobs_docstring,
2321
random_state=_random_state_docstring,
2422
)
2523
class ADASYN(BaseOverSampler):
@@ -50,14 +48,6 @@ class ADASYN(BaseOverSampler):
5048
:class:`~sklearn.neighbors.NearestNeighbors` but could be extended to
5149
any compatible class.
5250
53-
{n_jobs}
54-
55-
.. deprecated:: 0.10
56-
`n_jobs` has been deprecated in 0.10 and will be removed in 0.12.
57-
It was previously used to set `n_jobs` of nearest neighbors
58-
algorithm. From now on, you can pass an estimator where `n_jobs` is
59-
already set instead.
60-
6151
Attributes
6252
----------
6353
sampling_strategy_ : dict
@@ -128,7 +118,6 @@ class ADASYN(BaseOverSampler):
128118
Interval(numbers.Integral, 1, None, closed="left"),
129119
HasMethods(["kneighbors", "kneighbors_graph"]),
130120
],
131-
"n_jobs": [numbers.Integral, None],
132121
}
133122

134123
def __init__(
@@ -137,12 +126,10 @@ def __init__(
137126
sampling_strategy="auto",
138127
random_state=None,
139128
n_neighbors=5,
140-
n_jobs=None,
141129
):
142130
super().__init__(sampling_strategy=sampling_strategy)
143131
self.random_state = random_state
144132
self.n_neighbors = n_neighbors
145-
self.n_jobs = n_jobs
146133

147134
def _validate_estimator(self):
148135
"""Create the necessary objects for ADASYN"""
@@ -151,17 +138,6 @@ def _validate_estimator(self):
151138
)
152139

153140
def _fit_resample(self, X, y):
154-
# FIXME: to be removed in 0.12
155-
if self.n_jobs is not None:
156-
warnings.warn(
157-
(
158-
"The parameter `n_jobs` has been deprecated in 0.10 and will be"
159-
" removed in 0.12. You can pass an nearest neighbors estimator"
160-
" where `n_jobs` is already set instead."
161-
),
162-
FutureWarning,
163-
)
164-
165141
self._validate_estimator()
166142
random_state = check_random_state(self.random_state)
167143

0 commit comments

Comments
 (0)