Skip to content

ConvergenceWarnings cannot be turned off #29294

@user529481

Description

@user529481

Hi, I'm unable to turn off convergence warnings from GraphicalLassoCV.

I've tried most of the solutions from, and none of them worked (see below for actual implementations):
https://stackoverflow.com/questions/879173/how-to-ignore-deprecation-warnings-in-python
https://stackoverflow.com/questions/32612180/eliminating-warnings-from-scikit-learn/33812427#33812427
https://stackoverflow.com/questions/53968004/how-to-silence-all-sklearn-warning
https://stackoverflow.com/questions/14463277/how-to-disable-python-warnings

Contrary to what the designers of the sklearn's exceptions must have thought when it was implemented, some of us actually use stdout to log important information of the host program for diagnostics purposes. Flooding it with garbage that cannot be turned off, as is in the case with cross-validation, is not ok.

To briefly speak to the severity of the issue, the above sklearn-specific questions relating to suppressing warnings have been viewed ~500K times with combined ~400 upvotes, and dates back 7 years.

I've tried the following (n_jobs parameter does not appear to affect the result):

from sklearn.covariance import GraphicalLassoCV
import warnings
warnings.filterwarnings("ignore", category=ConvergenceWarning)

model = GraphicalLassoCV(n_jobs=4)
model = model.fit(data)
from sklearn.covariance import GraphicalLassoCV
import warnings
warnings.filterwarnings(action='ignore')

model = GraphicalLassoCV(n_jobs=4)
model = model.fit(data)
import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore", ConvergenceWarning)

    model = GraphicalLassoCV(n_jobs=4)
    model = model.fit(data)
from sklearn.covariance import GraphicalLassoCV
def warn(*args, **kwargs):
    pass
import warnings
warnings.warn = warn

model = GraphicalLassoCV(n_jobs=4)
model = model.fit(data)
import contextlib
import os, sys

@contextlib.contextmanager
def suppress_stdout():
    with open(os.devnull, 'w') as fnull:
        old_stdout = sys.stdout
        sys.stdout = fnull
        try:
            yield
        finally:
            sys.stdout = old_stdout

with suppress_stdout():
    model = GraphicalLassoCV(n_jobs=4)
    model = model.fit(data)
import logging
logging.captureWarnings(True)

logging.getLogger("py.warnings").setLevel(logging.ERROR)

model = GraphicalLassoCV(n_jobs=4)
model = model.fit(data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ModerateAnything that requires some knowledge of conventions and best practiceshelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions