【问题标题】:Error with json in Azure Machine Learning Studio with R with H2O package带有 R 和 H2O 包的 Azure 机器学习工作室中的 json 错误
【发布时间】:2020-01-22 01:16:28
【问题描述】:

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

我了解,当请求我的 predict 函数时,数据以 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,

【问题讨论】:

    标签: r h2o azure-machine-learning-studio azure-notebooks


    【解决方案1】:

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

    newdata <- as.data.frame(newdata)
    

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

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      • 2022-08-24
      • 2020-08-19
      • 1970-01-01
      • 2021-10-27
      相关资源
      最近更新 更多