iPhone app for RRS

By for January 13, 2016

Report Abuse
iPhone application template for making real-time predictions using Azure ML APIs
# Build a Predictive App for iPhone using Visual Studio and Azure ML # ## Overview ## In this tutorial, we will walk through creating an iOS app that can consume an Azure ML RRS API using Xamarin. [Xamarin](https://xamarin.com/) ships with Visual Studio. For this example, we will be using Visual Studio 2015. Note that you will need a Mac to run and test your app. ## Create the Web Service API ## First, we use the "Clustering: Group iris data" sample experiment from the Azure ML Gallery. We train the model, create a Predictive Experiment, then deploy it as a web service. (See [here](https://azure.microsoft.com/en-us/documentation/articles/machine-learning-walkthrough-5-publish-web-service/) for more on this process) We will call the Request-Response API created here from our iOS app to classify the category of Iris flower. ![](https://operationalizatio.blob.core.windows.net/publicimages/experiment.png) ## Create a Visual Studio Project ## In Visual Studio 2015, we create an IOS application: - Click on File -> New Project - Select iPhone under iOS - Click on Blank App (iPhone) - Set the Name to IrisClassifier - Click OK ![](https://operationalizatio.blob.core.windows.net/publicimages/newproject.png) ### Add References ### For this application, we will be using Xamarin’s MonoTouch.Dialog. For more on that, see here. Right-click on References in the Project Explorer, then add a reference to MonoTouch.Dialog-1. ![](https://operationalizatio.blob.core.windows.net/publicimages/referenece.png) Then, right-click, select NuGet Manager, and add NowtonSoft.Json. ### The Application Code ### The source code for this example can be found on [GitHub](https://github.com/raymondlaghaeian/IOSAppforRRS). Let’s go over the most important parts here. The key to this application is the “.json” file which defines what will be shown on the input screen of the App. It should include all the input fields that the Azure ML API needs to post a request. The fields should match the input fields as described in the Request/Response Help file of the API we created above. The help file is accessible after you deploy a web service. ![](https://operationalizatio.blob.core.windows.net/publicimages/json.png) The AppDialogue.cs file contains the code that instantiates the UI. The FinishedLaunching method which creates the screen and loads the JSON file look likes below. ![](https://operationalizatio.blob.core.windows.net/publicimages/finished.png) The Callback method is used to get a reference to the JSON file and loop through the input fields and extract the values. ![](https://operationalizatio.blob.core.windows.net/publicimages/callback.png) Finally, the call to the RRS API is made from the InvokeReqeustResponseService method. This includes the Azure ML API URL and Key. The code is very similar to the C# sample code on the RRS Help Page. ![](https://operationalizatio.blob.core.windows.net/publicimages/request.PNG) ## Test the Project ## To test the project, you need to connect to a Mac. I will not cover the steps here as they are explained in detail [here](http://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/). For this example, I used [Free Provisioning](http://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/free-provisioning/). After setting up the Mac and connecting to an iPhone, you can run the app. ![](https://operationalizatio.blob.core.windows.net/publicimages/iris1.jpg) Enter data, and submit the request. You can change the column names to be more descriptive. ![](https://operationalizatio.blob.core.windows.net/publicimages/iris2.jpg) After the request is processed, you should see the response from the web service API. ![](https://operationalizatio.blob.core.windows.net/publicimages/iris3.jpg) The Values key shows the classification of the Iris (Iris-versicolor) for this example. ## Summary ## In this tutorial, we used Visual Studio 2015 and Xamarin to create a simple iOS app that can use Azure ML APIs to do real-time predictions.