gpt4 book ai didi

python - 隐藏 scikit-learn ConvergenceWarning : "Increase the number of iterations (max_iter) or scale the data"

转载 作者:行者123 更新时间:2023-12-02 18:49:51 25 4
gpt4 key购买 nike

我正在使用 Python 来预测值并收到许多警告,例如:

Increase the number of iterations (max_iter) or scale the data asshown in:https://scikit-learn.org/stable/modules/preprocessing.html Please also refer to the documentation for alternative solver options:https://scikit-learn.org/stable/modules/linear_model.html#logistic-regressionn_iter_i = _check_optimize_result(C:\Users\ASMGX\anaconda3\lib\site-packages\sklearn\linear_model_logistic.py:762:ConvergenceWarning: lbfgs failed to converge (status=1): STOP: TOTALNO. of ITERATIONS REACHED LIMIT.

这会阻止我看到我自己的打印结果。

有什么办法可以阻止显示这些警告?

最佳答案

您可以使用 warnings -module 暂时抑制警告。所有警告或特定警告。

在这种情况下,scikit-learn 引发了一个 ConvergenceWarning所以我建议完全抑制这种类型的警告。该警告类位于 sklearn.exceptions.ConvergenceWarning 中,因此请预先导入它并使用上下文管理器 catch_warnings和函数 simplefilterignore警告,即不将其打印到屏幕上:

import warnings
from sklearn.exceptions import ConvergenceWarning

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=ConvergenceWarning)

optimizer_function_that_creates_warning()

您也可以全局忽略该特定警告以避免使用上下文管理器:

import warnings
warnings.simplefilter("ignore", category=ConvergenceWarning)

optimizer_function_that_creates_warning()

不过我建议使用上下文管理器,因为您确定在何处抑制警告。这样你就不会抑制来自意想不到的地方的警告。

关于python - 隐藏 scikit-learn ConvergenceWarning : "Increase the number of iterations (max_iter) or scale the data",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66938102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com