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

2024-04-18 04:44:12 发布

您现在位置:Python中文网/ 问答频道 /正文

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

例如,在执行以下操作时:

model.predict(frame_in)

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

^{pr2}$

python有没有一种方法可以得到未知级别的对象?谢谢。在

当使用h2o MOJOs时,有一个名为getTotalUnknownCategoricalLevelsSeen()的{a1},但我在h2o python文档中找不到类似的内容。在


Tags: 数据方法进度条in模型类型pythonapi列表
2条回答

你可以考虑H2O的GLRM(广义低阶模型)。它可以插补缺失的值。在

http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/glrm.html

最终临时捕获了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()

然后使用regex来筛选只包含列名和未查看值列表的输出行,然后使用另一个regex进行筛选以获得列表(然后删除空白和.split(',')以获得值的python字符串list)。也可以使用regex从同一行获取列名,并在元组列表中对它们。在

相关问题 更多 >