1
0
Форкнуть 0
Brianna Gerads 2015-07-10 12:59:30 -07:00
Родитель 2e6531efee e2f67e4d73
Коммит d591ac4d90
4 изменённых файлов: 39 добавлений и 31 удалений

Просмотреть файл

@ -3,9 +3,16 @@
##################################################################################################### #####################################################################################################
# IMPORTANT: need to compile all of consume, discover, publish functions before running this demo # IMPORTANT: need to compile all of consume, discover, publish functions before running this demo
setwd("C://Users/t-ritra/Documents/GitHub/Azure-MachineLearning-ClientLibrary-R/demo") setwd("C://Users/t-ritra/Github/Documents/Azure-MachineLearning-ClientLibrary-R/demo")
setwd("C://Users/t-alewa/Documents/Azure-MachineLearning-ClientLibrary-R/demo")
# test server
myID = "bbc91d900c3546b695d6507867fc72ae" myID = "bbc91d900c3546b695d6507867fc72ae"
myAuth = "ffc4b8d52c494e9eb42726b77112be88" myAuth = "ffc4b8d52c494e9eb42726b77112be88"
# internal server
myID = "3612640f27234eb7b2b91ac62e8b4a40"
myAuth = "abcbe14a958a40978f93aa0e0e71f5be"
test <- read.csv(file="test.csv") test <- read.csv(file="test.csv")
train <- read.csv(file="train.csv") train <- read.csv(file="train.csv")
@ -74,27 +81,34 @@ predictTitanic(1, "male", "20", "2", "0", "8.50")
# Publish the function # Publish the function
TitanicService <- publishWebService("predictTitanic", "TitanicDemo7-8", list("Pclass"="string", "Sex"="string", "Age"="int", "SibSp"="int", "Parch"="int", "Fare"="float"), list("survProb"="float"), myID, myAuth) # Go to https://metaanalytics001.cloudapp.net/Home/ViewWorkspace/bbc91d900c3546b695d6507867fc72ae?#Workspace/WebServiceGroups/listWebServiceGroups
TitanicService <- publishWebService("predictTitanic", "TitanicDemo7-9", list("Pclass"="string", "Sex"="string", "Age"="int", "SibSp"="int", "Parch"="int", "Fare"="float"), list("survProb"="float"), myID, myAuth) # to see published function
TitanicService <- publishWebService("predictTitanic", "TitanicDemo7-10", list("Pclass"="string", "Sex"="string", "Age"="int", "SibSp"="int", "Parch"="int", "Fare"="double"), list("survProb"="double"), myID, myAuth)
# Currently response is a list of three things: # Currently response is a list of two things:
# new web service details, default endpoint details, specific consumption function # new web service details, default endpoint details (using discovery functions)
# Rename the consumption function
consumeTitanic <- TitanicService[[3]]
# Discover the endpoints
# Go to help page
endpoints <- getEndpoints(myID, myAuth, TitanicService[[1]]["Id"], internalURL)
# Alternatively,
endpoints <- TitanicService[[2]]
# Use the new function, consumeList curried with the new web service details
# Slow initially as it makes the connection, but subsequent calls are faster
# as connection is left open
response <- consumeTitanic(list("1", "male", "20", "1", "0", "8.50"), list("1", "female", "20", "1", "0", "8.50"))
# data frame consumption
# Consume the new webservice
# First, consume with inputs as a list
# Slow initially as it makes the connection
response <- consumeLists(endpoints[[1]]["PrimaryKey"], paste(endpoints[[1]]["ApiLocation"], "/execute?api-version=2.0&details=true",sep=""), list("Pclass", "Sex", "Age", "SibSp", "Parch", "Fare"), list("1", "male", "20", "1", "0", "8.50"), list("1", "female", "20", "1", "0", "8.50"))
# Subsequent calls are faster as connection is left open
response2 <- consumeLists(endpoints[[1]]["PrimaryKey"], paste(endpoints[[1]]["ApiLocation"], "/execute?api-version=2.0&details=true",sep=""), list("Pclass", "Sex", "Age", "SibSp", "Parch", "Fare"), list("2", "male", "50", "1", "0", "8.50"), list("2", "female", "50", "1", "0", "8.50"))
# consume with inputs as dataframe
# creating test data.frame # creating test data.frame
demoDF <- data.frame("Pclass"=c(1,2,3), "Sex"=c("male","female","male"), "Age"=c("8","20", "50"), "Parch"=c(1,2,3), "SibSp"=c(1,2,3), "Fare"=c(10,7.5, 6)) demoDF <- data.frame("Pclass"=c(1,2,3), "Sex"=c("male","female","male"), "Age"=c("8","20", "50"), "Parch"=c(1,2,3), "SibSp"=c(1,1,1), "Fare"=c(10,7.5, 6))
responseDF <- consumeDataframe(TitanicService[[2]][[1]]$PrimaryKey, paste(TitanicService[[2]][[1]]$ApiLocation,"/execute?api-version=2.0&details=true",sep=""), demoDF)
responseDF <- consumeDataframe(TitanicService[[2]][[1]]$PrimaryKey, paste(TitanicService[[2]][[1]]$ApiLocation,"/execute?api-version=2.0&details=true",sep=""), demoDF) responseDF <- consumeDataframe(TitanicService[[2]][[1]]$PrimaryKey, paste(TitanicService[[2]][[1]]$ApiLocation,"/execute?api-version=2.0&details=true",sep=""), demoDF)
# Questions, comments, concerns?

Просмотреть файл

@ -153,27 +153,19 @@ consumeDataframe <- function(api_key, requestURL, valuesDF, globalParam="", batc
resultStored <- jsonlite::fromJSON(temp) resultStored <- jsonlite::fromJSON(temp)
resultList = resultStored$Results$output1$value$Values resultList = resultStored$Results$output1$value$Values
resultDF <- data.frame(resultList[,(ncol(resultList))]) resultDF <- data.frame(resultList[,(ncol(resultList))])
print(resultDF)
print(is.data.frame(resultDF))
if(length(df) != 0 && length(resultDF) != 0) { if(length(df) != 0 && length(resultDF) != 0) {
names(df) <- names(resultDF) names(df) <- names(resultDF)
} }
df <- rbind(df,resultDF) df <- rbind(df,resultDF)
colnames(df) <- "Scored probabilities" colnames(df) <- resultStored$Results$output1$value$ColumnNames
print("passed")
print(sprintf("%i %s %i %s", i,"out of",length(values),"processed")) print(sprintf("%i %s %i %s", i,"out of",length(values),"processed"))
valuebatch = list() valuebatch = list()
counter = 0 counter = 0
} }
counter = counter + 1 counter = counter + 1
} }
colnames(df) <- "Scored probabilities"
return(df) return(df)
resultStored <- jsonlite::fromJSON(resultStored)
resultDF <- data.frame(matrix(resultStored$Results$output1$value$Values))
colnames(resultDF) <- resultStored$Results$output1$value$ColumnNames
return(resultDF)
} }

Просмотреть файл

@ -8,6 +8,7 @@ epURLdet = "https://management-tm.azureml.net/workspaces/%s/webservices/%s/endpo
# remove in real version # remove in real version
testURL = "https://hiteshsm.cloudapp.net/workspaces/%s/webservices/%s/endpoints" testURL = "https://hiteshsm.cloudapp.net/workspaces/%s/webservices/%s/endpoints"
internalURL = "https://management.azureml-int.net/workspaces/%s/webservices/%s/endpoints"
############################################################# #############################################################
# Framework for making an HTTP request to the URL specified # Framework for making an HTTP request to the URL specified

Просмотреть файл

@ -1,7 +1,8 @@
################################################################ ################################################################
# String constants # String constants
################################################################ ################################################################
publishURL <- "https://hiteshsm.cloudapp.net/workspaces/%s/webservices/%s" ## REMOVE SSL IGNORING FOR REAL VERSION ## publishURL <- "https://management.azureml-int.net/workspaces/%s/webservices/%s" ## REMOVE SSL IGNORING FOR REAL VERSION ##
#publishURL <- "https://hiteshsm.cloudapp.net/workspaces/%s/webservices/%s" ## REMOVE SSL IGNORING FOR REAL VERSION ##
wrapper <- "inputDF <- maml.mapInputPort(1)\r\noutputDF <- matrix(ncol = %s, nrow = nrow(inputDF))\r\ncolnames(outputDF) <- list(%s)\r\noutputDF <- data.frame(outputDF)\r\nfor (file in list.files(\"src\")) {\r\n if (file == \"%s\") {\r\n load(\"src/%s\")\r\n for (item in names(dependencies)) {\r\n assign(item, dependencies[[item]])\r\n }\r\n }\r\n else {\r\n if (!(file %%in%% installed.packages()[,\"Package\"])) {\r\n install.packages(paste(\"src\", file, sep=\"/\"), lib=\".\", repos=NULL, verbose=TRUE)\r\n }\r\n library(strsplit(file, \"\\\\.\")[[1]][[1]], character.only=TRUE)\r\n }\r\n}\r\naction <- %s\r\n for (i in 1:nrow(inputDF)) {\r\n outputDF[i,] <- do.call(\"action\", as.list(inputDF[i,]))\r\n }\r\nmaml.mapOutputPort(\"outputDF\")" wrapper <- "inputDF <- maml.mapInputPort(1)\r\noutputDF <- matrix(ncol = %s, nrow = nrow(inputDF))\r\ncolnames(outputDF) <- list(%s)\r\noutputDF <- data.frame(outputDF)\r\nfor (file in list.files(\"src\")) {\r\n if (file == \"%s\") {\r\n load(\"src/%s\")\r\n for (item in names(dependencies)) {\r\n assign(item, dependencies[[item]])\r\n }\r\n }\r\n else {\r\n if (!(file %%in%% installed.packages()[,\"Package\"])) {\r\n install.packages(paste(\"src\", file, sep=\"/\"), lib=\".\", repos=NULL, verbose=TRUE)\r\n }\r\n library(strsplit(file, \"\\\\.\")[[1]][[1]], character.only=TRUE)\r\n }\r\n}\r\naction <- %s\r\n for (i in 1:nrow(inputDF)) {\r\n outputDF[i,] <- do.call(\"action\", as.list(inputDF[i,]))\r\n }\r\nmaml.mapOutputPort(\"outputDF\")"
@ -394,12 +395,12 @@ publishWebService <- function(functionName, serviceName, inputSchema, outputSche
# Use discovery functions to get default endpoint for immediate use # Use discovery functions to get default endpoint for immediate use
# switch to getEndpoints() later # switch to getEndpoints() later
defaultEP <- getEndpoints(wkID, authToken, newService["Id"], testURL) defaultEP <- getEndpoints(wkID, authToken, newService["Id"], internalURL)
# Curry relevant parameters to consumption function # Curry relevant parameters to consumption function
consumption <- functional::Curry(consumeLists, "api_key"=defaultEP[[1]]["PrimaryKey"], "requestURL"=paste(defaultEP[[1]]["ApiLocation"],"/execute?api-version=2.0&details=true",sep=""), "columnNames"=as.list(names(inputSchema))) #consumption <- functional::Curry(consumeLists, "api_key"=defaultEP[[1]]["PrimaryKey"], "requestURL"=paste(defaultEP[[1]]["ApiLocation"],"/execute?api-version=2.0&details=true",sep=""), "columnNames"=as.list(names(inputSchema)))
# currently returning list of webservice details, default endpoint details, consumption function, in that order # currently returning list of webservice details, default endpoint details, consumption function, in that order
return(list(newService, defaultEP, consumption)) return(list(newService, defaultEP))#, consumption))
} }