sklearn上的Lasso不会收敛

got*_*ota 9 python machine-learning least-squares scikit-learn

当我运行类似的东西

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)
Run Code Online (Sandbox Code Playgroud)

我收到错误:

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')
Run Code Online (Sandbox Code Playgroud)

有趣的是,A从来没有排名低效.(我认为)

kaz*_*ase 11

尝试增加tol.

文档:

tol:float,可选

优化的容差:如果更新小于tol,优化代码检查双重间隙的最优性并继续直到它小于tol.

在我的scikit-learn版本中,tol的默认值为0.0001.我假设您的公差非常小,以至于优化永远不会达到较低的值.


Gen*_*e M 6

有时帮助我摆脱警告的唯一一件事是显着增加迭代次数(显着增加训练时间)。

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).

  • 你所说的“不同模型”是什么?把名字留下来吧,我可以自己查一下,看看是否有用。谢谢! (2认同)