sklearn:关闭警告

新手上路,请多包涵

When I’m fitting sklearn ’s LogisticRegression using a 1 column python pandas DataFrame (not a Series 对象),我收到此警告:

 /Library/Python/2.7/site-packages/sklearn/preprocessing/label.py:125:
DataConversionWarning: A column-vector y was passed when a 1d array was
expected. Please change the shape of y to (n_samples, ), for example using
ravel().
y = column_or_1d(y, warn=True)

我知道我可以很容易地在我的代码中添加这个警告,但是我怎样才能关闭这些警告呢?

原文由 hlin117 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 908
2 个回答

正如 这里 发布的,

 with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    # Do stuff here

感谢上面的 Andreas 发布链接。

原文由 hlin117 发布,翻译遵循 CC BY-SA 3.0 许可协议

你可以使用这个:

 import warnings
from sklearn.exceptions import DataConversionWarning
warnings.filterwarnings(action='ignore', category=DataConversionWarning)

原文由 Jeffrey Zhou 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题