RandomizedSearchCV: warnings cannot be suppressed
See original GitHub issueDescription
I would like to suppress the warnings thrown by sklearn. This can be done while I was working on a single classifier, however, it failed on SearchCV task. I am wondering if this is designed for purpose and if there are any workarounds.
Steps/Code to Reproduce
File 1 (No warnings)
import warnings
import sklearn
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import RandomizedSearchCV
import pandas as pd
import numpy as np
x = np.random.normal(0, 1, (100, 100))
y = [0] * 50 + [1] * 50
if __name__ == "__main__":
warnings.filterwarnings("ignore")
clf = LogisticRegression()
clf.fit(x, y)
clf.predict(x)
print("done")
Run the code from terminal
File 2 (Warnings still exist)
import warnings
import sklearn
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import RandomizedSearchCV
import pandas as pd
import numpy as np
x = np.random.normal(0, 1, (100, 100))
y = [0] * 50 + [1] * 50
if __name__ == "__main__":
warnings.filterwarnings("ignore")
clf = LogisticRegression()
clf = RandomizedSearchCV(clf, {"C": [1,2]}, n_jobs=-1)
clf.fit(x, y)
clf.predict(x)
print("done")
Expected Results
should see done
from terminal. While the second file gave me multiple FutureWarning
Actual Results
As above
Versions
appnope==0.1.0
backcall==0.1.0
certifi==2018.11.29
Click==7.0
cycler==0.10.0
decorator==4.3.0
feather-format==0.4.0
ipykernel==5.1.0
ipython==7.2.0
ipython-genutils==0.2.0
jedi==0.13.2
jupyter-client==5.2.4
jupyter-core==4.4.0
kiwisolver==1.0.1
matplotlib==3.0.2
mkl-fft==1.0.6
mkl-random==1.0.2
numpy==1.15.4
pandas==0.23.4
parso==0.3.1
pexpect==4.6.0
pickleshare==0.7.5
prompt-toolkit==2.0.7
ptyprocess==0.6.0
pyarrow==0.11.1
Pygments==2.3.1
pyparsing==2.3.0
python-dateutil==2.7.5
pytz==2018.7
pyzmq==17.1.2
scikit-learn==0.20.2
scipy==1.1.0
six==1.12.0
tornado==5.1.1
traitlets==4.3.2
wcwidth==0.1.7
xlrd==1.2.0
Tested on 3.6.8 with MacOS 10.14
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Eliminating warnings from scikit-learn - python - Stack Overflow
I would like to ignore warnings from all packages when I am teaching, but scikit-learn seems to work around the use of the...
Read more >warnings — Warning control — Python 3.11.1 documentation
Repetitions of a particular warning for the same source location are typically suppressed. There are two stages in warning control: first, each time...
Read more >3.2. Tuning the hyper-parameters of an estimator - Scikit-learn
RandomizedSearchCV implements a randomized search over parameters, where each setting is sampled from a distribution over possible parameter values.
Read more >sklearn ignore warnings
This can be done by suppressing warning messages when your program is run. This can be achieved by explicitly configuring the Python warning...
Read more >mlflow.sklearn — MLflow 2.0.1 documentation
MLflow cannot find run information for other objects derived from a given prediction ... silent – If True , suppress all event logs...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Per @tomMoral 's comment, if you don’t want to completely disable warnings for everything, this “resolves” the issue with Python 3.10, sci-kit learn 1.0.2 on Ubuntu 20.04:
Hope this helps someone 😄
Any news on this? This reduces the usability of
RandomizedSearchCV
, since it hides useful information… SettingPYTHONWARNINGS
works, but seems like a quite clumsy workaround…