1

I notice some people fail to suppress sklearn warnings even with warnings handling. Interestingly, I experience a similar scenario only when n_job=-1.

Warning suppression works fine when n_job=1. Is there a way for n_job=-1?

import numpy as np
import sklearn.linear_model
import sklearn.model_selection

from sklearn.exceptions import ConvergenceWarning
import warnings
warnings.filterwarnings(action='ignore', category=ConvergenceWarning)

clf = sklearn.linear_model.ElasticNet(max_iter=1000000)

grid = {'alpha': np.logspace(-5, 0, 25), 'l1_ratio': np.logspace(-5, 0, 25)}
grid_search = sklearn.model_selection.GridSearchCV(clf, grid, cv=5, n_jobs=-1, verbose=1)
grid_search.fit(X, y)
Simon
  • 703
  • 2
  • 8
  • 19
  • Does this answer your question? [How to disable ConvergenceWarning using sklearn?](https://stackoverflow.com/questions/53784971/how-to-disable-convergencewarning-using-sklearn) – Syph Feb 25 '22 at 13:07
  • Please, tell me if my answer solved your issue or if you have found another way for suppressing the warning with `n_jobs = -1` – Syph Nov 15 '22 at 09:47

1 Answers1

0

I had the same issue with HalvinRandomSearch and this answer solved the problem.

I tried to specify the module to ignore as suggest in one of the comments below with "ignore::UserWarning:sklearn" but it doesn't work so I just ignore all UserWarning:

if not sys.warnoptions:
    warnings.simplefilter("ignore")
    os.environ["PYTHONWARNINGS"] = "ignore::UserWarning"
Syph
  • 99
  • 10