Skip to content

Liblinear convergence failure everywhere? #11536

Open

Description

@amueller

Recently we made liblinear report convergence failures.
Now this is reported in lots of places. I expect our users will start to see it everywhere. Should we change something? It's weird if most uses of LinearSVC result in a "failure" now.

Activity

  1. amueller commented on Jul 15, 2018

    @amueller
    MemberAuthor

    Also, it's pretty weird that SVC has max_iter=-1 and LinearSVC has max_iter=1000. Is there a reason for that?

  2. agramfort commented on Jul 16, 2018

    @agramfort
    Member

    good question. Looking at liblinear code it appears we don't expose the different stopping criteria they have and we added a max_iter parameter they don't seem to have.

    I have no idea why it was set to 1000. Was there any benchmark done?

  3. amueller commented on Jul 16, 2018

    @amueller
    MemberAuthor

    Not that I can remember...

  4. modified the milestones: 0.21, 0.20 on Jul 16, 2018
  5. GaelVaroquaux commented on Jul 16, 2018

    @GaelVaroquaux
    Member

    No strong opinion. Too many warnings means that users don't look at warnings.

    The only thing that I can suggest is adding an option to control this behavior. I don't really like adding options (the danger is to have too many), but it seems here that there is no one-size-suits-all choice.

  6. amueller commented on Jul 16, 2018

    @amueller
    MemberAuthor

    we could also increase the tol? @ogrisel asked if we have this warning for logistic regression as well or if we ignore it there.

  7. ogrisel commented on Jul 16, 2018

    @ogrisel
    Member

    Does this issue also happen with the LogisticRegression class?

  8. GaelVaroquaux commented on Jul 17, 2018

    @GaelVaroquaux
    Member

    I am -1 on increasing the tol: it will mean that many users will wait longer.

    I think that there should be an option to control convergence warnings.

  9. amueller commented on Jul 17, 2018

    @amueller
    MemberAuthor

    increasing the tol meaning a larger tol. So if anything people will wait shorter.

  10. GaelVaroquaux commented on Jul 17, 2018

    @GaelVaroquaux
    Member
  11. samronsin commented on Jul 17, 2018

    @samronsin
    Contributor

    Working on this.

  12. samronsin commented on Jul 17, 2018

    @samronsin
    Contributor

    @ogrisel indeed LogisticRegression is also potentially affected.

  13. 59 remaining items

  14. amueller commented on Dec 23, 2019

    @amueller
    MemberAuthor

    Also: we just changed our default away from liblinear...

    The question which kind of problems are "hard" is likely to depend on the solver, I think, or how you formulate the problem.

  15. smarie commented on Jan 16, 2020

    @smarie
    Contributor

    Also: we just changed our default away from liblinear...

    @amueller could you please point me to the corresponding issue/pr ? I did not see that in the master codebase. Thanks!

  16. smarie commented on Jan 17, 2020

    @smarie
    Contributor

    Ah ok I mistakenly thought that this was about SVC. Thanks!

  17. hermidalc commented on Mar 11, 2020

    @hermidalc
    Contributor

    if you have features with wildly different scales to others fitting the optimal hyperplane at a reasonable tolerance will get difficult.

    It depends a bit on what you mean by "difficult". You could probably do something like #15583 and solve the original optimization problem quite well. I'm not saying it's a good idea to not scale your data, I'm just saying it's totally possible to solve the optimization problem well despite the user giving you badly scaled data if your optimization algorithm is robust enough.

    To come back to this here’s some additional evidence challenging this belief when it comes to practical usage:

    From the creators of LIBSVM and LIBLINEAR:
    https://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf

    Section 2.2 Scaling
    Scaling before applying SVM is very important. Part 2 of Sarle’s Neural Networks FAQ Sarle (1997) explains the importance of this and most of considerations also ap- ply to SVM. The main advantage of scaling is to avoid attributes in greater numeric ranges dominating those in smaller numeric ranges. Another advantage is to avoid numerical difficulties during the calculation. Because kernel values usually depend on the inner products of feature vectors, e.g. the linear kernel and the polynomial ker- nel, large attribute values might cause numerical problems. We recommend linearly scaling each attribute to the range [−1, +1] or [0, 1].
    Of course we have to use the same method to scale both training and testing data. For example, suppose that we scaled the first attribute of training data from [−10, +10] to [−1, +1]. If the first attribute of testing data lies in the range [−11, +8], we must scale the testing data to [−1.1, +0.8]. See Appendix B for some real examples.

  18. amueller commented on Mar 13, 2020

    @amueller
    MemberAuthor

    @hermidalc I observed it to be a bit more stable than lbfgs in some settings I tried, see the preconditioning issue & pr.

    I'm not entirely sure how we can make the user experience better here :-/ I've seen plenty of convergence issues even after scaling, but I haven't had the time to compose them.

  19. adrinjalali commented on Apr 20, 2020

    @adrinjalali
    Member

    I'm trying to remove issues which have been around for more than 2 releases from the milestones. But this one seems to be pressing and you really care about it @amueller . Leaving it in the milestone for 0.24, but we really should be better at following up on these.

  20. modified the milestones: 0.23, 0.24 on Apr 20, 2020
  21. hermidalc commented on Apr 20, 2020

    @hermidalc
    Contributor

    @hermidalc I observed it to be a bit more stable than lbfgs in some settings I tried, see the preconditioning issue & pr.

    I'm not entirely sure how we can make the user experience better here :-/ I've seen plenty of convergence issues even after scaling, but I haven't had the time to compose them.

    I have to say @amueller I do agree with you more now. With various high-dimensional datasets I've been working with these last few months, I've been seeing frequent convergence issues with LinearSVC after properly transforming and scaling the data beforehand, even after setting the tol=1e-1 which is what LIBLINEAR has and setting max_iter=10000 or greater. The optimization algorithm appears to particularly have convergence issues when performing model selection over a range of C when higher values of like 1e2 or greater

    The exact same workflows with SVC(kernel='linear') generally do not have any convergence problems. While the scores from both models are usually somehwhat similar, even with LinearSVC not being able to converge, they aren't the same and for some datasets it's really different. So for L2-penalized linear classification where I previously used LinearSVC I'm now going back to SVC and SGDClassifier.

    The problem is that only LinearSVC can solve penalty='l1' and dual=False problems for e.g. SelectFromModel feature selection, so it would be important for scikit-learn to fix the issue with the implementation. Possibly SGDClassifier with penalty='l1' can be used instead?

    Maybe the latest LIBLINEAR code has updates/fixes that have corrected what is the underlying problem? Looks like the main liblinear code in sklearn is from back in 2014.

  22. removed this from the 0.24 milestone on Oct 15, 2020
  23. added
    Needs Decision
    and removed
    High Priority
    on Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions