当我运行类似下面的代码时:
import numpyfrom sklearn import linear_modelA= #somethingb= #somethingclf=linear_model.Lasso(alpha=0.015, fit_intercept=False, tol=0.00000000000001, max_iter=10000000000000, positive=True)clf.fit(A,b)
我得到了以下错误:
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 notconverge. You might want to increase the number of iterations' to increase the number of iterations')
有趣的是,A 矩阵从未出现秩缺陷。(我认为)
回答:
尝试增加 tol 的值。
根据文档:
tol : float, 可选
优化过程的容忍度:如果更新值小于 tol,优化代码会检查对偶间隙以判断是否达到最优,并继续运行直到对偶间隙小于 tol。
在我使用的 scikit-learn 版本中,tol 的默认值是 0.0001。我猜测你的容忍度设置得太小,以至于优化过程无法达到更低的值。