Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn: Turning off warnings

Tags:

When I'm fitting sklearn's LogisticRegression using a 1 column python pandas DataFrame (not a Series object), I get this warning:

/Library/Python/2.7/site-packages/sklearn/preprocessing/label.py:125:          DataConversionWarning: A column-vector y was passed when a 1d array was  expected. Please change the shape of y to (n_samples, ), for example using  ravel(). y = column_or_1d(y, warn=True) 

I know I could easily advert this warning in my code, but how can I turn off these warnings?

like image 584
hlin117 Avatar asked Mar 16 '15 20:03

hlin117


People also ask

How do you hide the Sklearn warning?

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.

What is DeprecationWarning in Python?

DeprecationWarning. Base category for warnings about deprecated features when those warnings are intended for other Python developers (ignored by default, unless triggered by code in __main__ ). SyntaxWarning. Base category for warnings about dubious syntactic features.

What is FutureWarning?

FutureWarning messages are designed to inform you about upcoming changes to default values for arguments in the scikit-learn API. FutureWarning messages can be ignored or suppressed as they do not halt the execution of your program.


1 Answers

You can use this:

import warnings from sklearn.exceptions import DataConversionWarning warnings.filterwarnings(action='ignore', category=DataConversionWarning) 
like image 116
Jeffrey Zhou Avatar answered Oct 02 '22 15:10

Jeffrey Zhou