Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Accessing Machine Learning Models via REST APIs

DZone's Guide to

Accessing Machine Learning Models via REST APIs

In this post we take a look at how developers can access Watson Machine Learning in the cloud via REST endpoints. Read on for the details.

· AI Zone ·
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

Watson Machine Learning can be used by data scientists to create models which can be managed and deployed on the IBM Cloud. Developers can access these models from applications, for example to run predictions.

I blogged about a sample scenario to predict whether people would have survived the Titanic accident based on their age, ticket class, sex and number of siblings and spouses on board the Titanic.

The screenshot shows the endpoint developers can use to access the deployed model via HTTP. In order to protect the endpoint, the credentials of the machine learning service are needed. With these credentials a bearer token is read that is needed for the actual prediction endpoint invocation.

ml-api-0

While this mechanism works for smaller teams and projects I’d guess that at some point you’d want API management capabilities so that developers don’t have to have the credentials of the machine learning service and so that you can better track the REST API invocations.

That’s why I have built a little demo that shows how to use API Connect on top of the Watson Machine Learning endpoint.

First I created a new API with only one POST REST API. In the assembly of this API there are four steps. First, the token is read from Watson Machine Learning. This requires the machine learning credentials. In the second step, the received token as well as the original content in the body field are put in a message JSON object. This message object can be accessed in the third step where the headers for the second invocation are set. In the last step the actual prediction endpoint is invoked.

ml-api-1

For the demo I secured the API with a client id only which developers can request via a portal. You could also use additionally secrets, OAuth and other security mechanisms.


ml-api-2

From the portal developers invoke the APIs.


ml-api-3

Since not everything fits on the screenshot above, here is another screenshot from a curl command.


ml-api-4

To find out more about Watson Machine Learning check out the IBM Data Science Experience. More information about API Connect can be found in the documentation and the available tutorials.

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

Topics:
developers ,watson ,rest api ,machine learning ,ml ,ai ,integration ,cloud

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}