使用OpenCPU访问自定义的R函数 [英] Using OpenCPU to access custom R function

查看:1577
本文介绍了使用OpenCPU访问自定义的R函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它加载的随机森林模型的R code,我期待建立一个函数

I have an R code which loads the RandomForest model, I am looking to create a function which

load(model)
randomforest_func = function(data) 
{
  data$pred = predict(model,data,type="prob")
  output = data.frame(data$customerid,data$pred[,2])
  return(output)
 }

我需要在Web服务器,在外部应用程序提供数据,并检索输出启用这个功能。

I need to make this function enabled in webserver, where an external application feeds data and retrieves the output.

的问题是,该模型必须是preloaded并且不能装载成R的env对于每个请求。

The problem is, the model needs to be preloaded and cannot load into R env for each request.

该功能需要支持并行连接。

The function needs to support parallel connections.

我尝试R中安装opencpu。

I tried installing opencpu in R.

以上code应该R和可在运行
    的http://本地主机:1234 / ocpu /

The above code should be running in R and available at http://localhost:1234/ocpu/

我现在修改了 opencpu.js 来指向这个URL和使用的jQuery 的功能下面。 ocpu.r_fun_call(randomforest_func,参数)

I now made changes to the opencpu.js to point to this URL and used the function in jquery to below. ocpu.r_fun_call("randomforest_func",parameters)

然而,这似乎不工作。

ocpu.r_fun_call 似乎并没有被访问第r脚本。

ocpu.r_fun_call does not seem to be accessing the R script.

我的问题是如何正确配置opencpu才能够访问randomforest_func

My question is how to correctly configure the opencpu to be able access the randomforest_func

推荐答案

应该帮助与部署它作为一个应用程序,使它更容易为任何外部应用程序消耗的服务。

This should help with deploying it as an app, making it easier for any external application to consume the services.

应该有助于包括型号。

This should help with including the model.

这篇关于使用OpenCPU访问自定义的R函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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