This was a pain to track down, as all suggested answers I've seen simply do not work. What finally worked for me was in the example code Early stopping of Stochastic Gradient Descent:
from sklearn.utils.testing import ignore_warnings
from sklearn.exceptions import ConvergenceWarning
You can then annotate a function like so:
@ignore_warnings(category=ConvergenceWarning)
def my_function():
# Code that triggers the warning
Note that you need not directly import anything from warnings
.
I think that's quite nice as it will only suppress warnings in the specific case where you need it, rather than globally.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…