Python sklearn 上的套索不收敛
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20681864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Lasso on sklearn does not converge
提问by gota
When I run something like
当我运行类似
import numpy
from sklearn import linear_model
A= #something
b= #something
clf=linear_model.Lasso(alpha=0.015, fit_intercept=False, tol=0.00000000000001,
max_iter=10000000000000, positive=True)
clf.fit(A,b)
I get the error:
我收到错误:
usr/local/lib/python2.7/dist-packages/scikit_learn-0.14.1-py2.7-linux-x86_64.egg/
sklearn/linear_model/coordinate_descent.py:418: UserWarning: Objective did not
converge. You might want to increase the number of iterations
' to increase the number of iterations')
The interesting thing is that A is never rank defficient. (I think)
有趣的是,A 从来都不是等级低效的。(我认为)
采纳答案by kazemakase
Try increasing tol.
尝试增加 tol。
From the documentation:
从文档:
tol : float, optional
The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.
tol : 浮动,可选
优化容忍度:如果更新小于 tol,则优化代码检查双重间隙的最优性,并继续直到它小于 tol。
The default for tol is 0.0001 on my version of scikit-learn. I assume that your tolerance is so small that the optimization never reaches a lower value.
在我的 scikit-learn 版本中,tol 的默认值是 0.0001。我假设您的容忍度非常小,以至于优化永远不会达到较低的值。
回答by Gene M
The only thing that SOMETIMES helped me to get rid of the warning was increasing the number of iterations significantly (with a significant increase of training time).
有时帮助我摆脱警告的唯一一件事是显着增加迭代次数(显着增加训练时间)。
Increasing the tolerance always led to the same warnings, but with larger values in them, and not to getting rid of the warnings. Not sure why.
增加容差总是导致相同的警告,但其中有更大的值,而不是摆脱警告。不知道为什么。
As an important analytical side note, I interpret getting this warning initially when using Lasso regression as a bad sign, regardless of what happens next.
For me it practically always occurred in the situation when the model was over-fitting, meaning that it performed well on the full training set itself, but then poorly during cross-validation and testing.
Regardless of whether I had supressed the warning (there is a way) or had gotten rid of it "naturally" by increasing the number of iterations, I almost always had to go back and simplify the set of features for Lasso to be effective (and in some cases to abandon Lasso altogether in favor of a different model).
作为一个重要的分析旁注,我认为在使用 Lasso 回归时最初收到此警告是一个不好的迹象,无论接下来会发生什么。
对我来说,它实际上总是发生在模型过度拟合的情况下,这意味着它在完整的训练集本身上表现良好,但在交叉验证和测试中表现不佳。
无论我是抑制了警告(有一种方法)还是通过增加迭代次数“自然地”摆脱它,我几乎总是不得不回去简化套索的功能集才能有效(并且在某些情况下完全放弃套索以支持不同的模型)。

