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

Skip to content

Conversation

@AlexandreSev
Copy link
Contributor

Reference Issues/PRs

Fixes #10866

What does this implement/fix? Explain your changes.

It makes convergence warnings appear when verbose = 0 in Logistic Regression.
It also updates a test to check that a warning is sent when it is needed.

Any other comments?

I also had to change test_return_train_score_warn in sklearn/model_selection/tests/test_search.py. The new warnings make this assertion to fail.
I am not sure that I perfectly understood this test, but I think it was not done to test convergence warnings.

@AlexandreSev AlexandreSev force-pushed the add_convergence_warning_to_linear_models branch from 3b2bae5 to cfee9c1 Compare March 28, 2018 14:19
n_iter=2, iid=False)]
estimators = [
GridSearchCV(
LinearSVC(random_state=0, max_iter=100000),
Copy link
Member

Choose a reason for hiding this comment

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

I would rather leave max_iter to its default. Can you try using @ignore_warnings(category=ConvergenceWarning)) on test_return_train_score_warn or something like assert_no_warnings(ignore_warnings(estimator.fit, category=ConvergenceWarning)(...))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank's for the review. It's done

# srand supports
n_iter_ = max(n_iter_)
if n_iter_ >= max_iter and verbose > 0:
if n_iter_ >= max_iter:
Copy link
Member

Choose a reason for hiding this comment

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

It would be great if you could estimate how much code is affected by this change. The best thing to do would be to add tests for the relevant estimators that they get a ConvergenceWarning.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

Yes, please add a similar test for LinearSVC

AlexandreSev added a commit to AlexandreSev/scikit-learn that referenced this pull request Mar 29, 2018
@AlexandreSev AlexandreSev changed the title [MRG] Add convergence warning to linear models [WIP] Add convergence warning to linear models Mar 29, 2018
@AlexandreSev AlexandreSev force-pushed the add_convergence_warning_to_linear_models branch from be9a6b3 to 23ecd24 Compare March 29, 2018 09:17
AlexandreSev added a commit to AlexandreSev/scikit-learn that referenced this pull request Mar 29, 2018
@AlexandreSev AlexandreSev changed the title [WIP] Add convergence warning to linear models [MRG] Add convergence warning to linear models Mar 29, 2018
@AlexandreSev
Copy link
Contributor Author

I added a test for LinearSVC and LinearSVR. They both use _fit_liblinear which has been changed.


def test_timeout():
a = svm.SVC(kernel=lambda x, y: np.dot(x, y.T), probability=True,
svc = svm.SVC(kernel=lambda x, y: np.dot(x, y.T), probability=True,
Copy link
Member

Choose a reason for hiding this comment

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

In general try to avoid changing something which is unrelated to the PR, it adds noise and makes reviewing less pleasant.



def test_convergence_warning_linear_svm():
# Test if a convergence warning is raised when verbose = 0.
Copy link
Member

Choose a reason for hiding this comment

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

Wow this is a very thorough test! I think this may be slightly overkill though, I would be happy with just checking the ConvergenceWarning with the default values of LinearSVC and LinearSVR.

estimators = [GridSearchCV(LinearSVC(random_state=0), grid, iid=False),
RandomizedSearchCV(LinearSVC(random_state=0), grid,
n_iter=2, iid=False)]
estimators = [
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned somewhere else, try to avoid changing unrelated things, especially if it is only cosmetic. Can you revert this change?

@AlexandreSev AlexandreSev force-pushed the add_convergence_warning_to_linear_models branch from 23ecd24 to 5d10ba5 Compare March 29, 2018 12:36
For lbfgs and liblinears solvers, the convergence warnings appeared
only when verbose was greater than 0, whereas they appeared with
verbose = 0 with other solvers.
Create test to check the convergence warning in logistic regression
and in linear svm.
Update `test_search` to ignore this convergence warning.
Fixes scikit-learn#10866
@AlexandreSev AlexandreSev force-pushed the add_convergence_warning_to_linear_models branch from 5d10ba5 to dcec4ba Compare March 29, 2018 12:46
@AlexandreSev
Copy link
Contributor Author

I rebased the different commits to have one clean commit which does not touch unrelated lines.
Sorry for these silly mistakes!

@lesteve
Copy link
Member

lesteve commented Mar 29, 2018

I rebased the different commits to have one clean commit which does not touch unrelated lines.
Sorry for these silly mistakes!

No worries, thanks for reverting the unwanted changes. For next time, conventions vary between projects, but in scikit-learn prefer if you don't squash your commits, because it makes it harder to see what has changed since the last time we looked at the PR. Also we use squash and merge so that PR always end up being a single commit anyway.

@lesteve
Copy link
Member

lesteve commented Mar 29, 2018

I pushed a minor tweak which I think makes the statement more readable. LGTM (as long as the CIs come back green).

@lesteve lesteve changed the title [MRG] Add convergence warning to linear models [MRG + 1] Add convergence warning to linear models Mar 29, 2018
@AlexandreSev
Copy link
Contributor Author

@lesteve Thank's for your help. I'll try to remember everything for the next contribution :)

@lesteve lesteve force-pushed the add_convergence_warning_to_linear_models branch from 2962148 to a59ed43 Compare March 29, 2018 14:37
@lesteve
Copy link
Member

lesteve commented Mar 29, 2018

@lesteve Thank's for your help. I'll try to remember everything for the next contribution :)

No worries that's part of the learning process :-). If you have not already
I invite you to look at our contribution guidelines.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

LGTM

@jnothman
Copy link
Member

jnothman commented Apr 1, 2018

Please add an entry to the change log at doc/whats_new/v0.20.rst under API Changes. Like the other entries there, please reference this pull request with :issue: and credit yourself (and other contributors if applicable) with :user:

@jnothman jnothman changed the title [MRG + 1] Add convergence warning to linear models [MRG + 2] Add convergence warning to linear models Apr 1, 2018
Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

Thanks

@jnothman jnothman merged commit cd76f9b into scikit-learn:master Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No warning when LogisticRegression does not converge

3 participants