简体   繁体   English

忽略来自Python模块(seaborn,sklearn)的警告

[英]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 . 但是,即使这样做了, seabornsklearn收到了许多警告。 I get UserWarning , DataConversionWarning and RuntimeWarning which, according to documentation, all inherit from Warning and should be covered by the above code. 我得到了UserWarningDataConversionWarningRuntimeWarning ,根据文档,它们都继承自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.

相关问题 python warnings.filterwarnings 不会忽略“import sklearn.ensemble”中的 DeprecationWarning - python warnings.filterwarnings does not ignore DeprecationWarning from 'import sklearn.ensemble' Python 记录器不显示来自外部模块的警告 - Python logger not show Warnings from external modules 如何修复“警告(来自警告模块):”使用Sklearn和Python - How to fix “Warning (from warnings module):” using Sklearn and Python 忽略python中的SonarQube警告 - Ignore SonarQube warnings in python 从命令行运行脚本时忽略 sklearn Gridsearch 中 n_jobs = -1 的警告不使用 warnings.simplefilter('ignore') - Ignoring warnings in sklearn Gridsearch with n_jobs = -1 when running the script from command line not working with warnings.simplefilter('ignore') 类型错误:sklearn ignore_warnings 需要 class 或类元组 - TypeError: sklearn ignore_warnings expects class or tuple of classes 如何忽略 Python 中的弃用警告 - How to ignore deprecation warnings in Python 无法在 Python 中安装 Seaborn 和其他模块 - Can't install Seaborn and other modules in Python 无法使用 warnings.filterwarnings("ignore") 抑制 Python 警告 - Cannot supress Python Warnings with warnings.filterwarnings("ignore") Python 子进程 — 如何忽略退出代码警告? - Python subprocess — how to ignore exit code warnings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM