Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings cannot be ignored #9179

Open
jaydu1 opened this issue Mar 26, 2024 · 1 comment
Open

Warnings cannot be ignored #9179

jaydu1 opened this issue Mar 26, 2024 · 1 comment

Comments

@jaydu1
Copy link

jaydu1 commented Mar 26, 2024

When running
statsmodels.discrete.discrete_model.NegativeBinomial(...).fit_regularized(...), I encountered a warning from

import warnings
warnings.warn(message, ConvergenceWarning)

Even though the results from model.summary look ok, the warning cannot be turned off and ignored with warnings.filterwarnings('ignore').
Below is the code that reproduces the problem:

import statsmodels as stats
import statsmodels.api as sm
import numpy as np
import warnings
with warnings.catch_warnings():
    warnings.filterwarnings("ignore")
    np.random.seed(0)
    Y = np.random.negative_binomial(1, 0.5, size=(100, ))
    
    X = np.random.normal( size=(100, 5))

    mod = stats.discrete.discrete_model.NegativeBinomial(Y, X).fit_regularized(
        method='l1', alpha=1e-12, trim_mode='off',
        method_kwargs={'warn_convergence': False}, qc_verbose=False, disp=False)

Thanks

@josef-pkt
Copy link
Member

Thanks, confirmed, (it's not notebook specific)
There is a hardcoded

        with warnings.catch_warnings():
                warnings.simplefilter("always")

but strange part is that it is when computing start_params, not in the main fit.
When I provide start_params in the example, then the warning does not show up.

my guess is that this was supposed to set "ignore" instead of "always" to suppress problems in start_params computation.

The same pattern shows up in many/all fit_regualrized in discrete_models
GenericZeroInflated fit_regularized does not do anything with warnings.
_get_start_params for regular fit in ZI subclasses uses "ignore": warnings.simplefilter("ignore", category=ConvergenceWarning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants