You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Leandro Hermida, Yuheng Wang, Kubra, Iris Zhang and mathurinm
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?
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.
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:
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.
@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'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.
@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.
Activity
amueller commentedon Jul 15, 2018
Also, it's pretty weird that SVC has
max_iter=-1and LinearSVC hasmax_iter=1000. Is there a reason for that?agramfort commentedon Jul 16, 2018
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?
amueller commentedon Jul 16, 2018
Not that I can remember...
GaelVaroquaux commentedon Jul 16, 2018
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.
amueller commentedon Jul 16, 2018
we could also increase the tol? @ogrisel asked if we have this warning for logistic regression as well or if we ignore it there.
ogrisel commentedon Jul 16, 2018
Does this issue also happen with the LogisticRegression class?
GaelVaroquaux commentedon Jul 17, 2018
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.
amueller commentedon Jul 17, 2018
increasing the tol meaning a larger tol. So if anything people will wait shorter.
GaelVaroquaux commentedon Jul 17, 2018
samronsin commentedon Jul 17, 2018
Working on this.
samronsin commentedon Jul 17, 2018
@ogrisel indeed
LogisticRegressionis also potentially affected.59 remaining items
amueller commentedon Dec 23, 2019
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.
smarie commentedon Jan 16, 2020
@amueller could you please point me to the corresponding issue/pr ? I did not see that in the master codebase. Thanks!
amueller commentedon Jan 16, 2020
@smarie I was referring to logisticregression:
https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html
smarie commentedon Jan 17, 2020
Ah ok I mistakenly thought that this was about SVC. Thanks!
hermidalc commentedon Mar 11, 2020
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.
amueller commentedon Mar 13, 2020
@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.
adrinjalali commentedon Apr 20, 2020
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.
hermidalc commentedon Apr 20, 2020
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
LinearSVCafter properly transforming and scaling the data beforehand, even after setting thetol=1e-1which is what LIBLINEAR has and settingmax_iter=10000or greater. The optimization algorithm appears to particularly have convergence issues when performing model selection over a range ofCwhen higher values of like 1e2 or greaterThe 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 withLinearSVCnot 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 usedLinearSVCI'm now going back toSVCandSGDClassifier.The problem is that only
LinearSVCcan solvepenalty='l1'anddual=Falseproblems for e.g.SelectFromModelfeature selection, so it would be important for scikit-learn to fix the issue with the implementation. PossiblySGDClassifierwithpenalty='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.