gpt4 book ai didi

python - 如何捕获未经训练的值 h2o python

转载 作者:行者123 更新时间:2023-12-05 06:37:31 25 4
gpt4 key购买 nike

在对 h2o 数据帧进行预测时如何捕获未知值?

例如,当做这样的事情时:

model.predict(frame_in)

在 h2o python api 中,在模型进行预测时加载进度条,然后输出一系列列表,详细说明模型预测特征的每个枚举类型所见的未知标签。例如。

/home/mapr/anaconda2/lib/python2.7/site-packages/h2o/job.py:69: UserWarning:
Test/Validation dataset column 'feature1' has levels not trained on: [, <values>]

有什么办法可以把这组未知关卡作为python对象获取吗?谢谢。

使用 h2o MOJO 时,有一个 java method称为 getTotalUnknownCategoricalLevelsSeen(),但我在 h2o python 文档中找不到类似的内容。

最佳答案

最终暂时捕获了 stderr 的警告输出。这是相关的片段:

import contextlib
import StringIO


@contextlib.contextmanager
def stderr_redirect(where):
"""
Temporarily redirect stdout to a specified python object
see https://stackoverflow.com/a/14197079
"""
sys.stderr = where
try:
yield where
finally:
sys.stderr = sys.__stderr__


# make prediction on data
with stderr_redirect(StringIO.StringIO()) as new_stderr:
preds = est.predict(frame_in)

print 'Prediction complete'
new_stderr.seek(0)
# capture any warning output
preds_stderr = new_stderr.read()

然后使用正则表达式过滤以仅输出包含列名和未见值列表的行,然后使用另一个正则表达式进行过滤以仅获取列表(然后我删除空格和 .split(',') 获取值的 python 字符串 list)。也可以使用正则表达式从同一行获取列名并将它们配对到元组列表中。

关于python - 如何捕获未经训练的值 h2o python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47702323/

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