如何使用Python API中计算并保存的H2OModel

2024-09-27 00:17:17 发布

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

我已经阅读了H2O文档有一段时间了,但是我还没有找到一个清楚的例子来说明如何使用Python API来加载model训练和保存。我在学下一个例子。在

import h2o
from h2o.estimators.naive_bayes import H2ONaiveBayesEstimator

model = H2ONaiveBayesEstimator()
h2o_df = h2o.import_file("http://s3.amazonaws.com/h2o-public-test-data/smalldata/airlines/allyears2k_headers.zip")
model.train(y = "IsDepDelayed", x = ["Year", "Origin"], 
            training_frame = h2o_df, 
            family = "binomial", 
            lambda_search = True, 
            max_active_predictors = 10)
h2o.save_model(model, path=models)

但是如果您检查官方的documentation,它说明您必须以POJO的形式从流UI下载模型。这是唯一的办法吗?或者,我可以通过python获得相同的结果吗?下面我展示了doc的示例,仅供参考。我需要一些指导。在

^{pr2}$

Tags: from文档importapidfmodel例子file
1条回答
网友
1楼 · 发布于 2024-09-27 00:17:17

save_model会将二进制模型保存到提供的文件系统中,但是,看看上面的Java应用程序,您似乎希望将model用于基于Java的评分应用程序中。在

因此,您应该使用h2o.download_pojo API将模型与genmodel jar文件一起保存到本地文件系统。API记录如下:

download_pojo(model, path=u'', get_jar=True)
Download the POJO for this model to the directory specified by the path; if the path is "", then dump to screen.

:param model: the model whose scoring POJO should be retrieved.
:param path: an absolute path to the directory where POJO should be saved.
:param get_jar: retrieve the h2o-genmodel.jar also.

一旦下载了POJO,就可以使用上面的示例应用程序来执行评分,并确保POJO类名和“modelClassName”与model type相同。在

相关问题 更多 >

    热门问题