【问题标题】:How to capture untrained-on values h2o python如何捕获未经训练的值 h2o python
【发布时间】:2017-12-07 19:23:36
【问题描述】:

在对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 MOJOs 时,有一个名为getTotalUnknownCategoricalLevelsSeen()java method,但我在h2o python 文档中找不到类似的内容。

【问题讨论】:

    标签: python h2o


    【解决方案1】:

    最终暂时捕获来自 stderr 的警告输出。这是相关的sn-p:

    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字符串@987654323 @ 值)。也可以使用正则表达式从同一行获取列名并将它们配对到元组列表中。

    【讨论】:

      【解决方案2】:

      您可以考虑 H2O 的 GLRM(广义低秩模型)。它可以估算缺失值。

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

      【讨论】:

        猜你喜欢
        • 2015-10-09
        • 1970-01-01
        • 2018-06-21
        • 2018-06-16
        • 2021-05-17
        • 2017-08-20
        • 1970-01-01
        • 1970-01-01
        • 2020-06-15
        相关资源
        最近更新 更多