scikit-learn - 沉默未定义度量警告
问题描述
UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples.
运行带有交叉验证的随机搜索管道确实有很多结果。我知道是什么导致了这种行为,建议设置为 0.0 分数目前对我来说很好,所以我现在只想让这个警告静音。
我试过了:
warnings.filterwarnings('ignore')
和
from sklearn.exceptions import UndefinedMetricWarning
warnings.filterwarnings('ignore', category=UndefinedMetricWarning)
但是我仍然收到这些警告,即使 StackOverflow 上的其他答案表明它们应该被这些行抑制(实际上它在前一段时间在笔记本中对我有用)。
该warnings.filterwarnings(...)
行位于import
语句的正下方,警告来自嵌套函数之一。
解决方案
按原样使用以下内容(复制粘贴):
from sklearn.exceptions import UndefinedMetricWarning
def warn(*args, **kwargs):
pass
import warnings
warnings.warn = warn
# more code here...
# more code here...
推荐阅读
- java - java-使用提交事务插入表
- python - 在 Amazon Linux 中,无法在 virtualenv 中安装 pandas 和 numpy
- linux - 如何在 Linux 中正确使用带有 Bluez 的 HCI 设备
- mongodb - mongodb 集合未加载到配置单元表中
- python-3.x - 在 LightGBM 中使用多个自定义指标
- amazon-web-services - 如何指定 ECS 服务名称
- node.js - Browsersync 不重新加载浏览器或注入 css
- opencv-python - 当我想运行 blinking_led.py 时出现此错误
- kubernetes - kubernetes create cinder pvc on Openstack Failed with error message: Invalid request due to wrong syntax or missing required parameters
- javascript - 我怎样才能让这个 javascript 工作不止一次?