Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eliminating warnings from scikit-learn [duplicate]

I would like to ignore warnings from all packages when I am teaching, but scikit-learn seems to work around the use of the warnings package to control this. For example:

with warnings.catch_warnings():     warnings.simplefilter("ignore")     from sklearn import preprocessing  /usr/local/lib/python3.5/site-packages/sklearn/utils/fixes.py:66: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead   if 'order' in inspect.getargspec(np.copy)[0]: /usr/local/lib/python3.5/site-packages/sklearn/utils/fixes.py:358: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead   if 'exist_ok' in inspect.getargspec(os.makedirs).args: 

Am I using this module incorrectly, or is sklearn doing something its not supposed to?

like image 447
Chris Fonnesbeck Avatar asked Sep 16 '15 14:09

Chris Fonnesbeck


People also ask

How do you stop Sklearn warnings?

with warnings. catch_warnings(): warnings. simplefilter("ignore") from sklearn import preprocessing /usr/local/lib/python3. 5/site-packages/sklearn/utils/fixes.

How do I stop deprecation warning in Python?

When nothing else works: $ pip install shutup . Then at the top of the code import shutup;shutup. please() . This will disable all warnings.


2 Answers

It annoys me to the extreme that sklearn forces warnings.

I started using this at the top of main.py:

def warn(*args, **kwargs):     pass import warnings warnings.warn = warn  #... import sklearn stuff... 
like image 184
joshterrell805 Avatar answered Sep 18 '22 02:09

joshterrell805


They have changed their warning policy in 2013. You can ignore warnings (also specific types) with something like this:

import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) 

//EDIT: in the comments below, Reed Richards points out that the filterwarnings call needs to be in the file that calls the function that gives the warning. I hope this helps those who experienced problems with this solution.

like image 27
Zakum Avatar answered Sep 21 '22 02:09

Zakum