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. (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?
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.
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. (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. (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:
if results.eigenvals[-1] < 1e-10:
#Do something.......
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.