1

我正在 Azure 机器学习工作室笔记本上使用带有 R 的 H2O 包部署模型。

我知道在请求我的预测函数时,数据以 json 格式传输,而当 mypred 函数中的 as.h2o () 命令尝试将 json 转换为 h2o 格式时,它不能并发生错误

训练模型

logistica_h2o <- h2o.glm(x = X, y = Y, 
                         training_frame = treino.h2o, 
                         family = "binomial)

获取工作区 ID 和令牌以及

workspace_id <- ""
authorization_token <- ""
ws <- workspace(workspace_id, authorization_token)

创建我的预测功能

newdata <- dados[,-32] #Remove response variable 

mypredict <- function(newdata){
  library(h2o)
  newdata <- as.h2o(newdata)
  as.data.frame(h2o.predict(logistica_h2o, newdata))
}

我在这里发布服务

ep <- publishWebService(ws = ws,
 fun = mypredict, 
 name = "PredicaoDeEntradaDeRonda", 
 inputSchema = dados[,-32], 
 data.frame=T) 

问题出现在这里

ewdata <-treino.h2o[1,-32]

pred <- consume(ep, newdata)
Error: No method asJSON S3 class: H2OFrame Traceback:

consume(ep, newdata)
callAPI(apiKey, requestUrl, requestsLists, globalParam, retryDelay, . .retry = .retry)
charToRaw(paste(toJSON(req, auto_unbox = TRUE, digits = 16), . collapse = "\n"))
paste(toJSON(req, auto_unbox = TRUE, digits = 16), collapse = "\n")
toJSON(req, auto_unbox = TRUE, digits = 16)
asJSON(x, dataframe = dataframe, Date = Date, POSIXt = POSIXt, . factor = factor, complex = complex, raw = raw, matrix = matrix, . auto_unbox = auto_unbox, digits = digits, na = na, null = null, . force = force, indent = indent, ...)
asJSON(x, dataframe = dataframe, Date = Date, POSIXt = POSIXt,
4

1 回答 1

0

我认为您需要先将其转换newdata为 R data.frame,然后再将其传递给consume()函数:

newdata <- as.data.frame(newdata)

这在这里看起来像同样的问题:https ://stackoverflow.com/a/49415285/5451344

于 2019-08-13T06:46:54.237 回答