Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecations 0.21 sgd tol #12239

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

Closed
Closed
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
4 changes: 2 additions & 2 deletions doc/modules/kernel_approximation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ a linear algorithm, for example a linear SVM::
SGDClassifier(alpha=0.0001, average=False, class_weight=None,
early_stopping=False, epsilon=0.1, eta0=0.0, fit_intercept=True,
l1_ratio=0.15, learning_rate='optimal', loss='hinge', max_iter=5,
n_iter=None, n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=None, shuffle=True, tol=None,
n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=None, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> clf.score(X_features, y)
1.0
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/linear_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ This way, we can solve the XOR problem with a linear classifier::
[1, 0, 1, 0],
[1, 1, 0, 0],
[1, 1, 1, 1]])
>>> clf = Perceptron(fit_intercept=False, max_iter=10, tol=None,
>>> clf = Perceptron(fit_intercept=False, max_iter=10, tol=0.001,
... shuffle=False).fit(X, y)

And the classifier "predictions" are perfect::
Expand Down
12 changes: 6 additions & 6 deletions sklearn/kernel_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class RBFSampler(BaseEstimator, TransformerMixin):
SGDClassifier(alpha=0.0001, average=False, class_weight=None,
early_stopping=False, epsilon=0.1, eta0=0.0, fit_intercept=True,
l1_ratio=0.15, learning_rate='optimal', loss='hinge', max_iter=5,
n_iter=None, n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=None, shuffle=True, tol=None,
n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=None, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> clf.score(X_features, y)
1.0
Expand Down Expand Up @@ -167,8 +167,8 @@ class SkewedChi2Sampler(BaseEstimator, TransformerMixin):
SGDClassifier(alpha=0.0001, average=False, class_weight=None,
early_stopping=False, epsilon=0.1, eta0=0.0, fit_intercept=True,
l1_ratio=0.15, learning_rate='optimal', loss='hinge', max_iter=10,
n_iter=None, n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=None, shuffle=True, tol=None,
n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=None, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> clf.score(X_features, y)
1.0
Expand Down Expand Up @@ -287,8 +287,8 @@ class AdditiveChi2Sampler(BaseEstimator, TransformerMixin):
SGDClassifier(alpha=0.0001, average=False, class_weight=None,
early_stopping=False, epsilon=0.1, eta0=0.0, fit_intercept=True,
l1_ratio=0.15, learning_rate='optimal', loss='hinge', max_iter=5,
n_iter=None, n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=0, shuffle=True, tol=None,
n_iter_no_change=5, n_jobs=None, penalty='l2',
power_t=0.5, random_state=0, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> clf.score(X_transformed, y) # doctest: +ELLIPSIS
0.9543...
Expand Down
56 changes: 18 additions & 38 deletions sklearn/linear_model/passive_aggressive.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ class PassiveAggressiveClassifier(BaseSGDClassifier):
Whether the intercept should be estimated or not. If False, the
data is assumed to be already centered.

max_iter : int, optional
max_iter : int, default=1000
The maximum number of passes over the training data (aka epochs).
It only impacts the behavior in the ``fit`` method, and not the
`partial_fit`.
Defaults to 5. Defaults to 1000 from 0.21, or if tol is not None.

.. versionadded:: 0.19

tol : float or None, optional
tol : float or None, default=1e-3
The stopping criterion. If it is not None, the iterations will stop
when (loss > previous_loss - tol). Defaults to None.
Defaults to 1e-3 from 0.21.
when (loss > previous_loss - tol).

.. versionadded:: 0.19

Expand Down Expand Up @@ -113,13 +111,6 @@ class PassiveAggressiveClassifier(BaseSGDClassifier):
.. versionadded:: 0.19
parameter *average* to use weights averaging in SGD

n_iter : int, optional
The number of passes over the training data (aka epochs).
Defaults to None. Deprecated, will be removed in 0.21.

.. versionchanged:: 0.19
Deprecated

Attributes
----------
coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes,\
Expand All @@ -143,13 +134,13 @@ class PassiveAggressiveClassifier(BaseSGDClassifier):
>>> clf.fit(X, y)
PassiveAggressiveClassifier(C=1.0, average=False, class_weight=None,
early_stopping=False, fit_intercept=True, loss='hinge',
max_iter=1000, n_iter=None, n_iter_no_change=5, n_jobs=None,
random_state=0, shuffle=True, tol=None,
max_iter=1000, n_iter_no_change=5, n_jobs=None,
random_state=0, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> print(clf.coef_)
[[0.29509834 0.33711843 0.56127352 0.60105546]]
[[-0.6543424 1.54603022 1.35361642 0.22199435]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really bad sign! I think we might have messed this up somehow.
I thought setting max_iter here meant we automatically set tol to 0.001 but apparently not?

>>> print(clf.intercept_)
[2.54153383]
[0.63310933]
>>> print(clf.predict([[0, 0, 0, 0]]))
[1]

Expand All @@ -166,11 +157,11 @@ class PassiveAggressiveClassifier(BaseSGDClassifier):
K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)

"""
def __init__(self, C=1.0, fit_intercept=True, max_iter=None, tol=None,
def __init__(self, C=1.0, fit_intercept=True, max_iter=1000, tol=1e-3,
early_stopping=False, validation_fraction=0.1,
n_iter_no_change=5, shuffle=True, verbose=0, loss="hinge",
n_jobs=None, random_state=None, warm_start=False,
class_weight=None, average=False, n_iter=None):
class_weight=None, average=False):
super(PassiveAggressiveClassifier, self).__init__(
penalty=None,
fit_intercept=fit_intercept,
Expand All @@ -186,8 +177,7 @@ def __init__(self, C=1.0, fit_intercept=True, max_iter=None, tol=None,
warm_start=warm_start,
class_weight=class_weight,
average=average,
n_jobs=n_jobs,
n_iter=n_iter)
n_jobs=n_jobs)

self.C = C
self.loss = loss
Expand Down Expand Up @@ -275,18 +265,16 @@ class PassiveAggressiveRegressor(BaseSGDRegressor):
Whether the intercept should be estimated or not. If False, the
data is assumed to be already centered. Defaults to True.

max_iter : int, optional
max_iter : int, default=1000
The maximum number of passes over the training data (aka epochs).
It only impacts the behavior in the ``fit`` method, and not the
`partial_fit`.
Defaults to 5. Defaults to 1000 from 0.21, or if tol is not None.

.. versionadded:: 0.19

tol : float or None, optional
tol : float or None, default=1e-3
The stopping criterion. If it is not None, the iterations will stop
when (loss > previous_loss - tol). Defaults to None.
Defaults to 1e-3 from 0.21.

.. versionadded:: 0.19

Expand Down Expand Up @@ -352,13 +340,6 @@ class PassiveAggressiveRegressor(BaseSGDRegressor):
.. versionadded:: 0.19
parameter *average* to use weights averaging in SGD

n_iter : int, optional
The number of passes over the training data (aka epochs).
Defaults to None. Deprecated, will be removed in 0.21.

.. versionchanged:: 0.19
Deprecated

Attributes
----------
coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes,\
Expand All @@ -378,11 +359,11 @@ class PassiveAggressiveRegressor(BaseSGDRegressor):
>>>
>>> X, y = make_regression(n_features=4, random_state=0)
>>> regr = PassiveAggressiveRegressor(max_iter=100, random_state=0)
>>> regr.fit(X, y)
>>> regr.fit(X, y) # doctest: +NORMALIZE_WHITESPACE
PassiveAggressiveRegressor(C=1.0, average=False, early_stopping=False,
epsilon=0.1, fit_intercept=True, loss='epsilon_insensitive',
max_iter=100, n_iter=None, n_iter_no_change=5,
random_state=0, shuffle=True, tol=None,
max_iter=100, n_iter_no_change=5,
random_state=0, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> print(regr.coef_)
[20.48736655 34.18818427 67.59122734 87.94731329]
Expand All @@ -403,12 +384,12 @@ class PassiveAggressiveRegressor(BaseSGDRegressor):
K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)

"""
def __init__(self, C=1.0, fit_intercept=True, max_iter=None, tol=None,
def __init__(self, C=1.0, fit_intercept=True, max_iter=1000, tol=1e-3,
early_stopping=False, validation_fraction=0.1,
n_iter_no_change=5, shuffle=True, verbose=0,
loss="epsilon_insensitive", epsilon=DEFAULT_EPSILON,
random_state=None, warm_start=False,
average=False, n_iter=None):
average=False):
super(PassiveAggressiveRegressor, self).__init__(
penalty=None,
l1_ratio=0,
Expand All @@ -424,8 +405,7 @@ def __init__(self, C=1.0, fit_intercept=True, max_iter=None, tol=None,
verbose=verbose,
random_state=random_state,
warm_start=warm_start,
average=average,
n_iter=n_iter)
average=average)
self.C = C
self.loss = loss

Expand Down
26 changes: 8 additions & 18 deletions sklearn/linear_model/perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ class Perceptron(BaseSGDClassifier):
Whether the intercept should be estimated or not. If False, the
data is assumed to be already centered. Defaults to True.

max_iter : int, optional
max_iter : int, default=1000
The maximum number of passes over the training data (aka epochs).
It only impacts the behavior in the ``fit`` method, and not the
`partial_fit`.
Defaults to 5. Defaults to 1000 from 0.21, or if tol is not None.

.. versionadded:: 0.19

tol : float or None, optional
tol : float or None, default=1e-3
The stopping criterion. If it is not None, the iterations will stop
when (loss > previous_loss - tol). Defaults to None.
Defaults to 1e-3 from 0.21.
when (loss > previous_loss - tol).

.. versionadded:: 0.19

Expand Down Expand Up @@ -97,13 +95,6 @@ class Perceptron(BaseSGDClassifier):
initialization, otherwise, just erase the previous solution. See
:term:`the Glossary <warm_start>`.

n_iter : int, optional
The number of passes over the training data (aka epochs).
Defaults to None. Deprecated, will be removed in 0.21.

.. versionchanged:: 0.19
Deprecated

Attributes
----------
coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes,\
Expand Down Expand Up @@ -131,9 +122,9 @@ class Perceptron(BaseSGDClassifier):
>>> from sklearn.linear_model import Perceptron
>>> X, y = load_digits(return_X_y=True)
>>> clf = Perceptron(tol=1e-3, random_state=0)
>>> clf.fit(X, y)
>>> clf.fit(X, y) # doctest: +NORMALIZE_WHITESPACE
Perceptron(alpha=0.0001, class_weight=None, early_stopping=False, eta0=1.0,
fit_intercept=True, max_iter=None, n_iter=None, n_iter_no_change=5,
fit_intercept=True, max_iter=1000, n_iter_no_change=5,
n_jobs=None, penalty=None, random_state=0, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)
>>> clf.score(X, y) # doctest: +ELLIPSIS
Expand All @@ -150,16 +141,15 @@ class Perceptron(BaseSGDClassifier):
https://en.wikipedia.org/wiki/Perceptron and references therein.
"""
def __init__(self, penalty=None, alpha=0.0001, fit_intercept=True,
max_iter=None, tol=None, shuffle=True, verbose=0, eta0=1.0,
max_iter=1000, tol=1e-3, shuffle=True, verbose=0, eta0=1.0,
n_jobs=None, random_state=0, early_stopping=False,
validation_fraction=0.1, n_iter_no_change=5,
class_weight=None, warm_start=False, n_iter=None):
class_weight=None, warm_start=False):
super(Perceptron, self).__init__(
loss="perceptron", penalty=penalty, alpha=alpha, l1_ratio=0,
fit_intercept=fit_intercept, max_iter=max_iter, tol=tol,
shuffle=shuffle, verbose=verbose, random_state=random_state,
learning_rate="constant", eta0=eta0, early_stopping=early_stopping,
validation_fraction=validation_fraction,
n_iter_no_change=n_iter_no_change, power_t=0.5,
warm_start=warm_start, class_weight=class_weight, n_jobs=n_jobs,
n_iter=n_iter)
warm_start=warm_start, class_weight=class_weight, n_jobs=n_jobs)
Loading