我正在使用 GridSearchCV 来优化 SVM 的超参数。我设置了最大迭代次数,因为我等不及几个小时才能得到结果。我知道会有收敛警告。我只是
想忽略这些警告而不显示在终端中。
提前致谢。
最佳答案
追查起来很痛苦,因为我见过的所有建议答案都不起作用。最终对我有用的是示例代码 Early stopping of Stochastic Gradient Descent :
from sklearn.utils.testing import ignore_warnings
from sklearn.exceptions import ConvergenceWarning
然后你可以像这样注释一个函数:
@ignore_warnings(category=ConvergenceWarning)
def my_function():
# Code that triggers the warning
请注意,您无需直接从
warnings
导入任何内容。 .我认为这很好,因为它只会在您需要它的特定情况下而不是在全局范围内抑制警告。
关于python - 如何使用 sklearn 禁用 ConvergenceWarning?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53784971/