Make an API for trains

October 14, 2015

Report Abuse
Creating an application programming interface (API) is easy in Azure ML Studio. Here is a step-by-step example for how to turn a model into a web service
The fun part of data science is making models. Turning those models into something that can be built into a web page or analytics code can be tough to do well. Luckily, Azure ML makes this process easy. This example steps you through how to do this in the Studio. 1. We start with a model that shows [feature engineering for train speed prediction][1]. If you open this in Studio, these instructions will walk you through how to publish it as a web service. 2. Select the "Train Model" module in the right hand column. This is the one that gave the best results of the three. Then click the "Set Up Web Service" button. This will collapse the experiment, which trains the model, to a scoring experiment. A scoring experiment will make predictions about new data points, but it won't modify the original model. ![set up web service button][2] 3. Click the "Deploy Web Service" button. You're done. This is all you need to do to create the web service. ![deploy web service button][3] 4. To use the deployed model in an application, you just need two pieces of information: the API key and a URL. The API key is prominently displayed on the API dashboard page that pops up when you deploy your web service. Anyone who has this key can call your web service, so don't pass it around to anyone unless you want to pay for them to use it. ![API key][4] 5. There are two URLs associated with the API, one for the Request/Response Service (RRS) and one for the Batch Execution Service (BES). The RRS makes predictions about one data point at a time. With BES, you provide a file full of data points, one per row, and the service makes predictions for the entire batch at one pass. If you have a lot of data points to get predictions for BES is a much faster and cheaper way to go. To find the URL for the RRS, click the "Request/Response" link. ![request response link][5] 6. The URL is displayed prominently. You can find the URL for the BES the same way. Both use the same API key. ![URL][6] If you go back and change your original model and deploy it again, the API key and URLs don't change. This allows to make changes to your original model after putting it out into the world. It's also good to keep in mind that if you are using someone else's web service, they can change what it does at any time with no warning. Make sure you trust the publisher. 7. Now you're ready to write an application that calls your model. Or better yet, bribe a web developer or software engineer friend to write one for you. Then you can spend your time building more models. This example is one of four that I talk about in a presentation called The Other Stuff: Getting from Machine Learning to Data Science. The rest of the examples from The Other Stuff are in [this collection][7], including [data visualization][8], [feature engineering][9], and [handling missing values][10]. If you found this helpful please take a look at [my other submissions][11] to the Cortana Analytics Gallery and [follow me on Twitter][12]. http://bit.ly/1M03iMs links to this page. I am a Senior Data Scientist at Microsoft. [1]: https://gallery.cortanaanalytics.com/Experiment/Create-useful-features-for-trains-1 [2]: https://github.com/brohrer-ms/public-hosting/raw/master/trains_api/web_service.png [3]: https://github.com/brohrer-ms/public-hosting/raw/master/trains_api/deploy_web_service.png [4]: https://github.com/brohrer-ms/public-hosting/raw/master/trains_api/api_key.png [5]: https://github.com/brohrer-ms/public-hosting/raw/master/trains_api/rrs.png [6]: https://github.com/brohrer-ms/public-hosting/raw/master/trains_api/web_service_url.png [7]: https://gallery.cortanaanalytics.com/Collection/The-other-stuff-Getting-from-machine-learning-to-data-science-1 [8]: https://gallery.cortanaanalytics.com/Experiment/Data-exploration-through-visualization-1 [9]: https://gallery.cortanaanalytics.com/Experiment/Create-useful-features-for-trains-1 [10]: https://gallery.cortanaanalytics.com/Experiment/Methods-for-handling-missing-values-1 [11]: https://gallery.cortanaanalytics.com/Home/Author?authorId=A45B9C46BE3D2A79C7BF21A0E91E205066C4F21409C28B5EB871E3018F4C298A [12]: https://twitter.com/intent/user?screen_name=_brohrer_