10000 MNT Clean-up deprecations for 1.7: average=0 in SGD (#31108) · scikit-learn/scikit-learn@6e08e64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e08e64

Browse files
authored
MNT Clean-up deprecations for 1.7: average=0 in SGD (#31108)
1 parent 6803bb3 commit 6e08e64

File tree

3 files changed

+1
-82
lines changed

3 files changed

+1
-82
lines changed

sklearn/linear_model/_stochastic_gradient.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class BaseSGD(SparseCoefMixin, BaseEstimator, metaclass=ABCMeta):
8787
"verbose": ["verbose"],
8888
"random_state": ["random_state"],
8989
"warm_start": ["boolean"],
90-
"average": [Interval(Integral, 0, None, closed="left"), "boolean"],
90+
"average": [Interval(Integral, 0, None, closed="neither"), "boolean"],
9191
}
9292

9393
def __init__(
@@ -597,17 +597,6 @@ def _partial_fit(
597597
reset=first_call,
598598
)
599599

600-
if first_call:
601-
# TODO(1.7) remove 0 from average parameter constraint
602-
if not isinstance(self.average, (bool, np.bool_)) and self.average == 0:
603-
warnings.warn(
604-
(
605-
"Passing average=0 to disable averaging is deprecated and will"
606-
" be removed in 1.7. Please use average=False instead."
607-
),
608-
FutureWarning,
609-
)
610-
611600
n_samples, n_features = X.shape
612601

613602
_check_partial_fit_first_call(self, classes)
@@ -683,16 +672,6 @@ def _fit(
683672
# delete the attribute otherwise _partial_fit thinks it's not the first call
684673
delattr(self, "classes_")
685674

686-
# TODO(1.7) remove 0 from average parameter constraint
687-
if not isinstance(self.average, (bool, np.bool_)) and self.average == 0:
688-
warnings.warn(
689-
(
690-
"Passing average=0 to disable averaging is deprecated and will be "
691-
"removed in 1.7. Please use average=False instead."
692-
),
693-
FutureWarning,
694-
)
695-
696675
# labels can be encoded as float, int, or string literals
697676
# np.unique sorts in asc order; largest class id is positive class
698677
y = validate_data(self, y=y)
@@ -1477,17 +1456,6 @@ def _partial_fit(
14771456
)
14781457
y = y.astype(X.dtype, copy=False)
14791458

1480-
if first_call:
1481-
# TODO(1.7) remove 0 from average parameter constraint
1482-
if not isinstance(self.average, (bool, np.bool_)) and self.average == 0:
1483-
warnings.warn(
1484-
(
1485-
"Passing average=0 to disable averaging is deprecated and will"
1486-
" be removed in 1.7. Please use average=False instead."
1487-
),
1488-
FutureWarning,
1489-
)
1490-
14911459
n_samples, n_features = X.shape
14921460

14931461
sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)
@@ -1565,16 +1533,6 @@ def _fit(
15651533
intercept_init=None,
15661534
sample_weight=None,
15671535
):
1568-
# TODO(1.7) remove 0 from average parameter constraint
1569-
if not isinstance(self.average, (bool, np.bool_)) and self.average == 0:
1570-
warnings.warn(
1571-
(
1572-
"Passing average=0 to disable averaging is deprecated and will be "
1573-
"removed in 1.7. Please use average=False instead."
1574-
),
1575-
FutureWarning,
1576-
)
1577-
15781536
if self.warm_start and getattr(self, "coef_", None) is not None:
15791537
if coef_init is None:
15801538
coef_init = self.coef_
@@ -2387,17 +2345,6 @@ def _partial_fit(
23872345
reset=first_call,
23882346
)
23892347

2390-
if first_call:
2391-
# TODO(1.7) remove 0 from average parameter constraint
2392-
if not isinstance(self.average, (bool, np.bool_)) and self.average == 0:
2393-
warnings.warn(
2394-
(
2395-
"Passing average=0 to disable averaging is deprecated and will"
2396-
" be removed in 1.7. Please use average=False instead."
2397-
),
2398-
FutureWarning,
2399-
)
2400-
24012348
n_features = X.shape[1]
24022349

24032350
# Allocate datastructures from input arguments
@@ -2488,16 +2435,6 @@ def _fit(
24882435
offset_init=None,
24892436
sample_weight=None,
24902437
):
2491-
# TODO(1.7) remove 0 from average parameter constraint
2492-
if not isinstance(self.average, (bool, np.bool_)) and self.average == 0:
2493-
warnings.warn(
2494-
(
2495-
"Passing average=0 to disable averaging is deprecated and will be "
2496-
"removed in 1.7. Please use average=False instead."
2497-
),
2498-
FutureWarning,
2499-
)
2500-
25012438
if self.warm_start and hasattr(self, "coef_"):
25022439
if coef_init is None:
25032440
coef_init = self.coef_

sklearn/linear_model/tests/test_passive_aggressive.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,3 @@ def test_regressor_undefined_methods():
266266
reg = PassiveAggressiveRegressor(max_iter=100)
267267
with pytest.raises(AttributeError):
268268
reg.transform(X)
269-
270-
271-
# TODO(1.7): remove
272-
@pytest.mark.parametrize(
273-
"Estimator", [PassiveAggressiveClassifier, PassiveAggressiveRegressor]
274-
)
275-
def test_passive_aggressive_deprecated_average(Estimator):
276-
est = Estimator(average=0)
277-
with pytest.warns(FutureWarning, match="average=0"):
278-
est.fit(X, y)

sklearn/linear_model/tests/test_sgd.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,14 +2165,6 @@ def test_sgd_numerical_consistency(SGDEstimator):
21652165
assert_allclose(sgd_64.coef_, sgd_32.coef_)
21662166

21672167

2168-
# TODO(1.7): remove
2169-
@pytest.mark.parametrize("Estimator", [SGDClassifier, SGDRegressor, SGDOneClassSVM])
2170-
def test_passive_aggressive_deprecated_average(Estimator):
2171-
est = Estimator(average=0)
2172-
with pytest.warns(FutureWarning, match="average=0"):
2173-
est.fit(X, Y)
2174-
2175-
21762168
def test_sgd_one_class_svm_estimator_type():
21772169
"""Check that SGDOneClassSVM has the correct estimator type.
21782170

0 commit comments

Comments
 (0)
0