如何修复LogisticRegressionCV中的不收敛


13

我正在使用scikit-learn对一组数据执行交叉验证并进行交叉验证(约有14个参数,且具有> 7000个标准化观测值)。我也有一个目标分类器,其值为1或0。

我的问题是,无论使用什么求解器,我都会不断收到收敛警告...

model1 = linear_model.LogisticRegressionCV(cv=10,verbose=1,n_jobs=-1,scoring='roc_auc',solver='newton-cg',penalty='l2')

/home/b/anaconda/lib/python2.7/site-packages/scipy/optimize/linesearch.py:285: LineSearchWarning: The line search algorithm did not converge
  warn('The line search algorithm did not converge', LineSearchWarning)
/home/b/anaconda/lib/python2.7/site-packages/sklearn/utils/optimize.py:193: UserWarning: Line Search failed


model2 = linear_model.LogisticRegressionCV(cv=10,verbose=1,n_jobs=-1,scoring='roc_auc',solver='sag',penalty='l2')

max_iter reached after 2 seconds
max_iter reached after 2 seconds
max_iter reached after 2 seconds
max_iter reached after 2 seconds
max_iter reached after 2 seconds
max_iter reached after 2 seconds
max_iter reached after 2 second

model3 = linear_model.LogisticRegressionCV(cv=10,verbose=1,n_jobs=-1,scoring='roc_auc',solver='lbfgs',penalty='l2')

/home/b/anaconda/lib/python2.7/site-packages/sklearn/linear_model/logistic.py:701: UserWarning: lbfgs failed to converge. Increase the number of iterations.
  warnings.warn("lbfgs failed to converge. Increase the number "

model4 = linear_model.LogisticRegressionCV(cv=10,verbose=1,n_jobs=-1,scoring='roc_auc',solver='liblinear',penalty='l2')

    cg reaches trust region boundary
iter 18 act 1.382e+06 pre 1.213e+06 delta 1.860e+01 f 7.500e+06 |g| 1.696e+06 CG   8
iter  2 act 1.891e+06 pre 1.553e+06 delta 1.060e-01 f 1.397e+07 |g| 1.208e+08 CG   4
iter  4 act 2.757e+04 pre 2.618e+04 delta 1.063e-01 f 1.177e+07 |g| 2.354e+07 CG   4
iter 18 act 1.659e+04 pre 1.597e+04 delta 1.506e+01 f 7.205e+06 |g| 4.078e+06 CG   4
cg reaches trust region boundary
iter  7 act 1.117e+05 pre 1.090e+05 delta 4.146e-01 f 1.161e+07 |g| 9.522e+05 CG   4
iter 31 act 1.748e+03 pre 1.813e+03 delta 2.423e+01 f 6.228e+05 |g| 5.657e+03 CG  14

我需要怎么做才能停止收到警告?


我不知道这是完全分离还是接近分离的情况
Sycorax说

Answers:


13

您可以通过应用程序的建议来增加max_iter参数。但请记住,逻辑模型也可能根本无法适应您的数据。


2
我不得不将max_tr增大到4000,但这确实成功了。谢谢!
user3188040 2015年

@ user3188040您花了多长时间跑步?
戴夫·刘

我是scikit的新手。如何将max_tr(max_iter?)“碰撞”到4000?
罗恩·詹森-我们都是莫妮卡

创建LogisticRegression对象时,可以更改max_iter值。MODEL1 = linear_model.LogisticRegressionCV(max_iter = 4000)
psychonomics
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.