RevolutionAnalytics / AzureML

An R interface to AzureML(https://studio.azureml.net/) experiments, datasets, and web services.
Other
46 stars 22 forks source link

added 'publish_model_as_web_service' function #46

Closed rmhorton closed 8 years ago

rmhorton commented 8 years ago

Modified from publishWebService and updateWebService; publish_model_as_web_service creates a web service given a model (lm, rpart, etc.)

bwlewis commented 8 years ago

@rmhorton brings up the excellent point that the default behavior of 'consume' evaluates a function row by row through sets of scalar arguments. If the function knows how to work on a data frame (like predict, for example), then passing the entire input data frame into the function in one shot is much more efficient.

I was just blindly following the old AzureML 'publishWebService' method, perhaps we should have been more critical of its approach.

Anyway, I tried to graft in a way to support this efficiency improvement while preserving all of the old syntax. Try out the latest commit to the 'dev' branch:

devtools::install_github("RevolutionAnalytics/AzureML", ref="dev")

and in particular see the examples for publishWebService. I think, for example, that the following example achieves what you're doing with this PR but in a somewhat more general way:

  set.seed(1)
  m <- lm(Ozone ~ ., data=airquality[sample(nrow(airquality), 100),])
  # Define a prediction function based on the model:
  fun <- function(newdata)
  {
    predict(m, newdata=newdata)
  }
  # Note the easy definition of inputSchema and use of the data.frame argument.
  ep <- publishWebService(ws, fun=fun, name="Ozone",
                          inputSchema=lapply(airquality, typeof),
                          outputSchema=list(ans="numeric"),
                          data.frame=TRUE)
  ans = consume(ep, airquality)$ans
  plot(ans, airquality$Ozone)
  deleteWebService(ws, "Ozone")

Thoughts?

andrie commented 8 years ago

Status update:

  1. @bwlewis has now implemented a variant of the proposed functionality. See ?publishWebservice for examples
  2. We will not merge the pull request as it stands

However, @rmhorton, it would be great if you can test the newly added functionality and comment on how well it serves what you have in mind.