R h2o以MOJO或POJO格式从磁盘加载已保存的模型 [英] R h2o load a saved model from disk in MOJO or POJO format

查看:821
本文介绍了R h2o以MOJO或POJO格式从磁盘加载已保存的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在追赶 h2o 的MOJO和POJO模型格式。我可以在MOJO / POJO中保存模型

I'm catching up on h2o's MOJO and POJO model format. I'm able to save a model in MOJO/POJO with

h2o.download_mojo(model, path = "/media/somewhere/tmp") # ok
h2o.download_pojo(model, path = "/media/somewhere/tmp") # ok

将一个名为 mymodel.zip mymodel.java 的对象写入目录。

which writes an object with name like mymodel.zip or mymodel.java to the directory.

然而,我不清楚如何将它读回R中的服务器。我试过了,

However, it's not clear to me how to read it back into the server in R. I tried,

saved_model2 <- h2o.loadModel("/media/somewhere/tmp/mymodel.java") # not work
saved_model3 <- h2o.loadModel("/media/somewhere/tmp/mymodel.zip") # not work

但是收到了错误信息,这样,

but got error msg like this,

ERROR: Unexpected HTTP Status code: 400 Bad Request (url = http://localhost:54321/99/Models.bin/)

java.lang.IllegalArgumentException
 [1] "java.lang.IllegalArgumentException: Missing magic number 0x1CED at stream start"  
....
Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page,  : 

ERROR MESSAGE:

Missing magic number 0x1CED at stream start


推荐答案

如果您想在R中对H2O模型进行预测,那么您有两种选择(您选择哪种方法)取决于你的用例):

If you are looking to make predictions on an H2O model in R, then you have two options (which method you choose depends on your use-case):


  1. 你可以使用二进制模型而不是MOJO(或POJO)。对于此方法,使用 h2o.saveModel()将模型导出到磁盘,然后使用 h2o.loadModel()并使用预测(模型,测试)进行预测。

  2. 如果您仍然希望将模型导出到 MOJO(或POJO)格式,您可以使用 h2o.predict_json() R中的函数用于生成预测。但是,测试数据必须以JSON格式提供。有关详细信息,请参阅此功能的文档。

  1. You can use a binary model instead of a MOJO (or POJO). For this method, you export the model to disk using h2o.saveModel() and load it back in using h2o.loadModel() and make predictions using predict(model, test).
  2. If you's still prefer to export a model to MOJO (or POJO) format, you can use the h2o.predict_json() function in R to generate predictions. The test data must be provided in JSON format, however. See the documentation on this function for details.

这篇关于R h2o以MOJO或POJO格式从磁盘加载已保存的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆