This notebook demonstrates some of the capabilities of the AzureML
package:
The target audience should have a basic understanding of the Azure Machine Learning studio. Specifically, you should:
If you are completely new to Azure ML, the Tutorial for Data Scientists can help you get started. All results as shown here are from my own Azure ML workspace.
Note that you don't have to specify own workspace ID and authorization token to run the code.
In [1]:
library(AzureML)
In [2]:
# Connect to the workspace
ws <- workspace()
In [3]:
# list first several datasets in my workspace
head(datasets(ws, filter = "sample")$Name)
Out[3]:
In [4]:
# download datasets
movies <- download.datasets(ws, name = "Movie Ratings")
head(movies)
Out[4]:
In [5]:
options(repr.plot.width = 6, repr.plot.height = 4)
hist(movies$Rating, main = "Rating", xlab = NULL)
In [6]:
airquality[1:10,]
Out[6]:
In [7]:
# uploading R data frame to Azure ML workspace
mydata <- airquality[1:10,]
# information about the uploaded dataset in the workspace will be returned
upload.dataset(mydata, ws, name = "my air quality")
Out[7]:
In [8]:
# download to check its content
head(download.datasets(ws, name = "my air quality"))
Out[8]:
In [9]:
# delete dataset
delete.datasets(ws, name = "my air quality")
Out[9]:
The "Airport Codes Dataset" is one of the dafault datasets in Azure ML. This example shows that the default datasets cannot be deleted.
In [10]:
# delete Azure sample dataset: not allowed
# Uncomment the following line to see the failure report
# delete.datasets(ws, name = "Airport Codes Dataset")
In [11]:
# experiments
exps <- experiments(ws)
head(
with(exps, data.frame(Description, ExperimentId, Creator, stringsAsFactors = FALSE))
)
#head(cbind(Description = exps$Description, ExperimentId = exps$ExperimentId, Creator = exps$Creator))
Out[11]:
You can also filter by using the experiments() function with the "filter" argument.
In [12]:
# check sample experiments
e <- experiments(ws, filter = "samples")
head(e$Creator)
head(cbind(e$Description, e$ExperimentId))
Out[12]:
Out[12]:
You can also download intermediate data from an experiment. To do this you need information for four variables:
To obtain this information, follow these simple steps
In [13]:
# download intermediate data
# Replace the code below with the snipped provided by the AzureML Studio
#exp_data <- download.intermediate.dataset(ws = ws,
# experiment = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
# node_id = "xxxxxxxx-xxx-xxx-xxxx-xxxxxxxxxxxx-xxx",
# port_name = "Results dataset",
# data_type_id = "GenericCSV")
#head(exp_data)
The AzureML
package also allows a very concise way of consuming the web service. All you need is to provide the web service ID and the workspace information. Then use consume()
to consume the service from any R terminal (as long as you have internet access).
For illustration purpose, fit a linear model and deploy a web service based on the model.
If you encounter the error Requires external zip utility. Please install zip, ensure it's on your path and try again
while running this on Windows, you can install RTools and add the install directory to the system path. For example, if it's installed in C:\Tools
, you should add C:\Tools\bin
to your system path and then restart R.
In [14]:
# load the package
library(MASS)
# fit a model using all variables except medv as predictors
lm1 <- lm(medv ~ ., data = Boston)
# define predict function
mypredict <- function(newdata){
predict(lm1, newdata)
}
# test the prediction function
newdata <- Boston[1:10, ]
# Publish the service
ep <- publishWebService(ws = ws,
fun = mypredict,
name = "HousePricePrediction",
inputSchema = newdata)
str(ep)
In [15]:
# consume
consume(ep, newdata)
Out[15]:
The AzureML
package also has a vignette Getting Started with the AzureML Package that covers a wider range of examples.
You can also take a look at the help for ?publishWebservice
Created by a Microsoft Employee.
Copyright © Microsoft. All Rights Reserved.