Data Science in the Cloud with Microsoft Azure Machine Learning and R Stephen F Elston Data Science in the Cloud with Microsoft Azure Machine Learning and R by Stephen F Elston Copyright © 2015 O’Reilly Media, Inc All rights reserved Printed in the United States of America Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O’Reilly books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safaribooksonline.com) For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com Editor: Shannon Cutt Production Editor: Melanie Yarbrough Copyeditor: Charles Roumeliotis Proofreader: Melanie Yarbrough Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest February 2015: First Edition Revision History for the First Edition 2015-01-26: First Release While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work Use of the information and instructions contained in this work is at your own risk If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights 978-1-491-91960-6 [LSI] Data Science in the Cloud with Microsoft Azure Machine Learning and R Introduction Recently, Microsoft launched the Azure Machine Learning cloud platform — Azure ML Azure ML provides an easy-to-use and powerful set of cloudbased data transformation and machine learning tools This report covers the basics of manipulating data, as well as constructing and evaluating models in Azure ML, illustrated with a data science example Before we get started, here are a few of the benefits Azure ML provides for machine learning solutions: Solutions can be quickly deployed as web services Models run in a highly scalable cloud environment Code and data are maintained in a secure cloud environment Available algorithms and data transformations are extendable using the R language for solution-specific functionality Throughout this report, we’ll perform the required data manipulation then construct and evaluate a regression model for a bicycle sharing demand dataset You can follow along by downloading the code and data provided below Afterwards, we’ll review how to publish your trained models as web services in the Azure cloud Downloads For our example, we will be using the Bike Rental UCI dataset available in Azure ML This data is also preloaded in the Azure ML Studio environment, or you can download this data as a csv file from the UCI website The reference for this data is Fanaee-T, Hadi, and Gama, Joao, “Event labeling combining ensemble detectors and background knowledge,” Progress in Artificial Intelligence (2013): pp 1-15, Springer Berlin Heidelberg The R code for our example can be found at GitHub Working Between Azure ML and RStudio When you are working between AzureML and RStudio, it is helpful to your preliminary editing, testing, and debugging in RStudio This report assumes the reader is familiar with the basics of R If you are not familiar with using R in Azure ML you should check out the following resources: Quick Start Guide to R in AzureML Video introduction to R with Azure Machine Learning Video tutorial of another simple data science example The R source code for the data science example in this report can be run in either Azure ML or RStudio Read the comments in the source files to see the changes required to work between these two environments Overview of Azure ML This section provides a short overview of Azure Machine Learning You can find more detail and specifics, including tutorials, at the Microsoft Azure web page In subsequent sections, we include specific examples of the concepts presented here, as we work through our data science example Figure 30 Box plot of the residuals for the neural network regression model by hour The box plot shows that the residuals of the neural network model exhibit some significant outliers, both on the positive and negative side Comparing these residuals to Figure 26, the outliers are not as extreme The details of the mean residual by hour and by month can be seen below in Figure 31 Figure 31 Median residuals by hour of the day and month count for the neural network regression model The results in Figure 31 confirm the presence of some negative residuals at certain hours of the day; compared to Figure 27, these figures look quite similar In summary, there may be a tradeoff between bias in the results and dispersion of the residuals; such phenomena are common More investigation is required to fully understand this problem Using an R Model in Azure ML In this section, you will learn how to incorporate an R language model into your Azure ML workflow For a schematic view of an R language model in an Azure ML workflow, see Figure We’ve added two new Execute R Script modules to our experiment We also use the copy and paste feature to add another Execute R Script module with the evaluation code The resulting workflow is shown in Figure 32 Figure 32 Experiment workflow with R model, with predict and evaluate modules added on the right In this example, we’ll try a support vector machine (SVM) regression model, using the ksvm() function from the kernlab package The first Execute R Script module computes the model from the training data, using the following code: ## ## ## ## This code computes a random forest model This code is s intended to run in an Azure ML Execute R Script module It can be tested in RStudio by now executing the Azure ML specific code ## Source the zipped utility file source("src/utilities.R") ## Read in the dataset BikeShare