Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore statsmodels Maximum Likelihood convergence warning?

I was trying to find the optimal parameter order by using a loop:

d = 1    
for p in range(3):
    for q in range(3):
        try:
           order = (p, 0, q)
           params = (p, d, q)
           arima_mod = ARIMA(ts.dropna(), order).fit(method = 'css-mle', disp = 0)
                arima_mod_aics[params] = arima_mod.aic
            except:
                pass

and I have received the message:

/usr/local/lib/python2.7/dist-packages/statsmodels-0.6.1-py2.7-linux-x86_64.egg/statsmodels/base/model.py:466: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
"Check mle_retvals", ConvergenceWarning)

I would like to ignore this warning, what should I do? Any suggestion?

Thanks in advance.

like image 437
Jellomima Avatar asked Dec 23 '15 22:12

Jellomima


3 Answers

To specifically ignore ConvergenceWarnings:

import warnings
from statsmodels.tools.sm_exceptions import ConvergenceWarning
warnings.simplefilter('ignore', ConvergenceWarning)
like image 164
1'' Avatar answered Nov 26 '22 13:11

1''


See this example from the statsmodels sourceforge, especially In [17]:.

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore")
    # Line that is not converging
    likev = mdf.profile_re(0, dist_low=0.1, dist_high=0.1)
like image 38
tmthydvnprt Avatar answered Nov 26 '22 13:11

tmthydvnprt


A clean way to do it is to use the included warn_convergence. You can pass it to fit method like so:

arima.fit(method_kwargs={"warn_convergence": False})
like image 43
ItCantBe Avatar answered Nov 26 '22 15:11

ItCantBe