[英]Ignore warnings in from Python modules (seaborn, sklearn)
There are many questions related to the question title above and all basically tell you to do: 与上面的问题标题相关的问题很多,所有这些基本上都告诉您要做:
import warnings
warnings.filterwarnings('ignore')
and to make sure this is placed before the first import. 并确保将其放置在首次导入之前 。
However, even after doing this I get many warnings from seaborn
and sklearn
. 但是,即使这样做了,
seaborn
和sklearn
收到了许多警告。 I get UserWarning
, DataConversionWarning
and RuntimeWarning
which, according to documentation, all inherit from Warning
and should be covered by the above code. 我得到了
UserWarning
, DataConversionWarning
和RuntimeWarning
,根据文档,它们都继承自Warning
并且应该包含在上面的代码中。
Is there another way to hide those warnings? 还有其他隐藏这些警告的方法吗? (I cannot really solve most of them anyway)
(我还是不能解决大多数问题)
EDIT 编辑
Example 1: 范例1:
C:\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py:645: DataConversionWarning: Data with input dtype int32, int64 were all converted to float64 by StandardScaler.
return self.partial_fit(X, y)
Example 2 例子2
C:\Anaconda3\lib\site-packages\seaborn\distributions.py:340: UserWarning: Attempted to set non-positive bottom ylim on a log-scaled axis.
Invalid limit will be ignored.
ax.set_ylim(0, auto=None)
Example2 例题
It's a bit hard to track down; 很难追踪; seaborn imports statsmodels.
seaborn进口统计模型。 And in
statsmodels/tools/sm_exceptions.py
you find this line 然后在
statsmodels/tools/sm_exceptions.py
找到这一行
warnings.simplefilter('always', category=UserWarning)
in which reverses any previous setting for user warnings. 其中会反转用户警告的任何先前设置。
A solution for now would be to remove that line or to set the warning state after the import of seaborn (and hence statsmodels). 一种用于现在的解决办法是删除该行或seaborn的导入后 ,设置警告状态(并因此statsmodels)。 In a future version of statsmodels this will be fixed by PR 4712 , so using the development version of statsmodels would also be an option.
在statsmodels的未来版本中,此问题将由PR 4712修复,因此也可以选择使用statsmodels的开发版本。
Example1 例1
I did not find a way to reproduce the first example from sklearn
; 我没有找到从
sklearn
复制第一个示例的sklearn
; so that may or may not have a different reason. 因此,可能有或没有不同的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.