简体   繁体   English

如何通过OLS回归输出摘要检测python中的特定警告

[英]How to detect a specific warning in python via OLS Regression output summary

Note: This is NOT a duplicate because one of the posts does not reference how to find my specific error with if statement implementation as I want. 注意:这不是重复的,因为其中一个帖子没有引用如何使用if语句实现找到我的特定错误。 (two warnings and detection of only one of them) (两个警告和仅检测其中一个)

How can I detect a specific warning in the OLS regression output so that I can utilize it in a if statement to do another regression? 如何在OLS回归输出中检测到特定警告,以便我可以在if语句中使用它来进行另一次回归?

There is another warning which I want to ignore, so I just want to pay attention to the specific warning: 还有一个我想忽略的警告,所以我只想注意具体的警告:

[2] The smallest eigenvalue is 0. This might indicate that there are strong multicollinearity problems or that the design matrix is singular.

Ex: Warning [2] shown below the image. 例如:图像下方显示警告[2]。 在此输入图像描述

What I am looking for is the simplest way to implement something like this pseudo code below: 我正在寻找的是实现类似下面的伪代码的最简单的方法:

If (OLS output has Warning [2])
         do something.........

Note: This is NOT a duplicate because one of the posts does not reference how to find my specific error with if statement implementation as I want. 注意:这不是重复的,因为其中一个帖子没有引用如何使用if语句实现找到我的特定错误。 (two warnings and detection of only one of them) (两个警告和仅检测其中一个)

There isn't an attribute of the results object which will contain the warnings. 结果对象没有包含警告的属性。 This is because the warning text is generated on the fly when the summary method is called. 这是因为调用summary方法时会立即生成警告文本。 (See here for the relevant code) (参见此处获取相关代码)

Instead you will have to check the value of the smallest eigenvalue yourself. 相反,您必须自己检查最小特征值的值。 The limit on the smallest eigenvalue that statsmodels uses is 1e-10 so the equivalent code for you would be: statsmodels使用的最小特征值的限制是1e-10,所以你的等效代码是:

if results.eigenvals[-1] < 1e-10:
    #Do something.......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM