Closed rmhorton closed 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?
Status update:
?publishWebservice
for examplesHowever, @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.
Modified from
publishWebService
andupdateWebService
;publish_model_as_web_service
creates a web service given a model (lm, rpart, etc.)