如何修复Statsmodel警告:“最大数量的迭代次数已超过“ [英] How to fix Statsmodel warning: "Maximum no. of iterations has exceeded"

查看:2613
本文介绍了如何修复Statsmodel警告:“最大数量的迭代次数已超过“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Anaconda,并且正在尝试逻辑回归.加载训练数据集并执行回归后.然后我收到以下警告消息.

train_cols = data.columns[1:]
logit = sm.Logit(data['harmful'], data[train_cols])
result = logit.fit() 
Warning: Maximum number of iterations has been exceeded.
     Current function value: 0.000004
     Iterations: 35
C:\Users\dell\Anaconda\lib\site-packages\statsmodels\base\model.py:466: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals"Check mle_retvals", ConvergenceWarning)

为什么我会收到此警告,该如何解决? 谢谢!

解决方案

有两种可能性

1)困难的优化问题:通常,Logit收敛速度非常快,并且默认的迭代次数设置得很低.在大多数情况下,在对fit的调用中添加较大的maxiter关键字或将先前的结果重新调整为start_params即可.

2)由于这是Logit,因此可能存在完全分离或准完全分离的情况.在这种情况下,某些参数可能会变为无穷大,并且优化会在某个收敛或停止条件下停止. Logit检测到完全分离的简单情况,并引发了异常,但是可能存在未检测到的部分分离.通过完美的分离,您可以在某些或所有情况下获得完美的可预测性,这对于预测很有用,但会导致估计和识别参数时出现问题. 例如,此处 https://stats. stackexchange.com/questions/11109/how-to-deal-with-perfect-separation-in-logistic-regression 在statsmodels github问题上还存在一些常见问题,例如极端情况和此类问题.

I am using Anaconda and I am trying logistic regression. After loading training data set and performed the regression. Then I got the following warning message.

train_cols = data.columns[1:]
logit = sm.Logit(data['harmful'], data[train_cols])
result = logit.fit() 
Warning: Maximum number of iterations has been exceeded.
     Current function value: 0.000004
     Iterations: 35
C:\Users\dell\Anaconda\lib\site-packages\statsmodels\base\model.py:466: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals"Check mle_retvals", ConvergenceWarning)

Why do I get this warning and how can I fix this? Thanks!

解决方案

There are two possibilities

1) difficult optimization problem: Usually Logit converges very fast and the default number of iteration is set very low. Adding a larger maxiter keyword in the call to fit or refitting with the previous result as start_params helps in most cases.

2) Since this is Logit, it is possible that there is complete separation, or quasi-complete separation. In this case some parameters might go off to infinity and the optimization stops at some convergence or stopping criterion. Logit detect the simple case of full separation and raises an exception, but there could be partial separation that is not detected. With perfect separation you get perfect predictability for some or all cases, which is useful for prediction but causes problems in estimating and identifying the parameters. More information is for example here https://stats.stackexchange.com/questions/11109/how-to-deal-with-perfect-separation-in-logistic-regression There are also several FAQ issues on the statsmodels github issues for corner cases and problems like this.

这篇关于如何修复Statsmodel警告:“最大数量的迭代次数已超过“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆