R Shiny中的h2o mojo预测 [英] h2o mojo predict in R Shiny

查看:245
本文介绍了R Shiny中的h2o mojo预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我已经用尽了整个互联网,以查找有关实施h2o mojo模型以在RShiny中进行预测的查询示例/答案.我们创建了许多模型,希望在用户输入值的RShiny前端中预测分数.但是,使用以下代码实现预测后,我们会得到

I think I have exhausted the entire internet looking for an example / answer to my query regarding implementing a h2o mojo model to predict within RShiny. We have created a bunch of models, and wish to predict scores in a RShiny front end where users enter values. However, with the following code to implement the prediction we get an error of

警告:checkForRemoteErrors中的错误:6个节点产生了错误;第一的 错误:没有方法asJSON S3类:H2OFrame

Warning: Error in checkForRemoteErrors: 6 nodes produced errors; first error: No method asJSON S3 class: H2OFrame

dataInput <- dfName
dataInput <- toJSON(dataInput)

rawPred <- as.data.frame(h2o.predict_json(model= "folder/mojo_model.zip",  json = dataInput, genmodelpath = "folder/h2o-genmodel.jar"))

任何人都可以提供一些帮助吗? 谢谢, Siobhan

Can anyone help with some pointers? Thanks, Siobhan

推荐答案

这不是一个有问题的问题.该错误表明您正在尝试在H2OFrame(而不是R data.frame)上使用toJSON(),因为 jsonlite 库不支持该功能,该操作将不起作用.

This is not a Shiny issue. The error indicates that you're trying to use toJSON() on an H2OFrame (instead of an R data.frame), which will not work because the jsonlite library does not support that.

相反,您可以使用以下命令将H2OFrame转换为data.frame:

Instead you can convert the H2OFrame to a data.frame using:

dataInput <- toJSON(as.data.frame(dataInput))

由于我没有尝试过,所以我不能保证toJSON()将为h2o.predict_json()生成正确的输入,因此您必须自己尝试一下.请注意,这可能是唯一可行的方法,如果它是1行data.frame,因为h2o.predict_json()函数需要单行数据,编码为JSON.如果您想对多个记录进行评分,则必须循环遍历这些行.如果由于某些原因toJSON()没有为您提供正确的格式,那么您可以在此处从data.frame手动创建JSON字符串.

I can't guarantee that toJSON() will generate the correct input for h2o.predict_json() since I have not tried that, so you will have to try it out yourself. Note that the only way this may work is if this is a 1-row data.frame because the h2o.predict_json() function expects a single row of data, encoded as JSON. If you're trying to score multiple records, you'd have to loop over the rows. If for some reason toJSON() doesn't give you the right format, then you can use a function I wrote in this post here to create the JSON string from a data.frame manually.

有一个门票已打开,以创建一个更好的h2o.predict_json()版本将支持根据MOJO对数据帧(具有多行)进行预测,而无需先转换为JSON.这样便可以避免完全处理JSON.

There is a ticket open to create a better version of h2o.predict_json() that will support making predictions from a MOJO on data frames (with multiple rows) without having to convert to JSON first. This will make it so you can avoid dealing with JSON altogether.

一种替代方法是使用 H2O二进制模型(而不是MOJO)以及标准的predict()函数.这里唯一的要求是必须将模型加载到H2O群集内存中.

An alternative is to use a H2O binary model instead of a MOJO, along with the standard predict() function. The only requirement here is that the model must be loaded into H2O cluster memory.

这篇关于R Shiny中的h2o mojo预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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