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

Skip to content
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/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ Linear, kernelized and related models
underlying implementation is broken. Use :class:`linear_model.Lasso` instead.
:issue:`9837` by `Alexandre Gramfort`_.

- ``n_iter_`` may vary from previous releases in
:class:`linear_model.LogisticRegression` with ``solver='lbfgs'`` and
:class:`linear_model.HuberRegressor`. For Scipy <= 1.0.0, the optimizer could
perform more than the requested maximum number of iterations. Now both
estimators will report at most ``max_iter`` iterations even if more were
performed. :issue:`10723` by `Joel Nothman`_.

Metrics

- Deprecate ``reorder`` parameter in :func:`metrics.auc` as it's no longer required
Expand Down
10 changes: 8 additions & 2 deletions sklearn/linear_model/huber.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ class HuberRegressor(LinearModel, RegressorMixin, BaseEstimator):

n_iter_ : int
Number of iterations that fmin_l_bfgs_b has run for.
Not available if SciPy version is 0.9 and below.

.. versionchanged:: 0.20

In SciPy <= 1.0.0 the number of lbfgs iterations may exceed
``max_iter``. ``n_iter_`` will now report at most ``max_iter``.

outliers_ : array, shape (n_samples,)
A boolean mask which is set to True where the samples are identified
Expand Down Expand Up @@ -264,7 +268,9 @@ def fit(self, X, y, sample_weight=None):
raise ValueError("HuberRegressor convergence failed:"
" l-BFGS-b solver terminated with %s"
% dict_['task'].decode('ascii'))
self.n_iter_ = dict_['nit']
# In scipy <= 1.0.0, nit may exceed maxiter.
# See https://github.com/scipy/scipy/issues/7854.
self.n_iter_ = min(dict_['nit'], self.max_iter)
self.scale_ = parameters[-1]
if self.fit_intercept:
self.intercept_ = parameters[-2]
Expand Down
9 changes: 8 additions & 1 deletion sklearn/linear_model/logistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,9 @@ def logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True,
if info["warnflag"] == 1 and verbose > 0:
warnings.warn("lbfgs failed to converge. Increase the number "
"of iterations.", ConvergenceWarning)
n_iter_i = info['nit'] - 1
# In scipy <= 1.0.0, nit may exceed maxiter.
# See https://github.com/scipy/scipy/issues/7854.
n_iter_i = min(info['nit'], max_iter)
elif solver == 'newton-cg':
args = (X, target, 1. / C, sample_weight)
w0, n_iter_i = newton_cg(hess, func, grad, w0, args=args,
Expand Down Expand Up @@ -1109,6 +1111,11 @@ class LogisticRegression(BaseEstimator, LinearClassifierMixin,
it returns only 1 element. For liblinear solver, only the maximum
number of iteration across all classes is given.

.. versionchanged:: 0.20

In SciPy <= 1.0.0 the number of lbfgs iterations may exceed
``max_iter``. ``n_iter_`` will now report at most ``max_iter``.

See also
--------
SGDClassifier : incrementally trained logistic regression (when given
Expand Down
7 changes: 7 additions & 0 deletions sklearn/linear_model/tests/test_huber.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def test_huber_equals_lr_for_high_epsilon():
assert_almost_equal(huber.intercept_, lr.intercept_, 2)


def test_huber_max_iter():
X, y = make_regression_with_outliers()
huber = HuberRegressor(max_iter=1)
huber.fit(X, y)
assert huber.n_iter_ == huber.max_iter


def test_huber_gradient():
# Test that the gradient calculated by _huber_loss_and_gradient is correct
rng = np.random.RandomState(1)
Expand Down