如何捕获未经训练的值 h2o python
How to capture untrained-on values h2o python
在 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
s 时,有一个名为 getTotalUnknownCategoricalLevelsSeen()
的 java method,但我在 h2o python
文档中找不到类似的内容。
暂时捕获了 stderr 的警告输出。这是相关的片段:
import contextlib
import StringIO
@contextlib.contextmanager
def stderr_redirect(where):
"""
Temporarily redirect stdout to a specified python object
see
"""
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
个值)。也可以使用正则表达式从同一行获取列名并将它们配对成元组列表。
您可能会考虑 H2O 的 GLRM(广义低秩模型)。它可以估算缺失值。
http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/glrm.html
在 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
s 时,有一个名为 getTotalUnknownCategoricalLevelsSeen()
的 java method,但我在 h2o python
文档中找不到类似的内容。
暂时捕获了 stderr 的警告输出。这是相关的片段:
import contextlib
import StringIO
@contextlib.contextmanager
def stderr_redirect(where):
"""
Temporarily redirect stdout to a specified python object
see
"""
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
个值)。也可以使用正则表达式从同一行获取列名并将它们配对成元组列表。
您可能会考虑 H2O 的 GLRM(广义低秩模型)。它可以估算缺失值。
http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/glrm.html