Azure Machine Learning – Episode III

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




This article is a third one in a series of articles related to introduction to Azure Machine Learning for Developers.

When working with Azure Machine Learning you will soon or later want to publish the trained model as a Web Service. However as developer you will expect some way to design your web service contract. Exactly this requirement seem not to be solved on some developer agnostic intuitive way.

This post describes shortly how to do that. Following picture shows some experiment, which compares two different models. On the right side of the picture I used two ProjectColumn shapes and one additional ScoreModel.


First ProjectColumn shape one is connected to the dataset and projects a single feature.


Then I connected trained model output to the Score Model. This connection will ensure that scoredLabel and scoreProbabibily values flow to the second ProjectColumn shape. So I can choose that two to be projected in the second ProjectColumn shape.


At the end, I published the input od ScoredModel (feature with name ‘number’) as Web Service Input. And finally I published output (scoredLabel and scoredProbability) of second ProjectColumn  shape as Web Service output.

The published Web Service is not really well designed as you would expect it in the world of SOA or microservices. But it can easily be consumed.


ScoreData scoreData = new ScoreData()
          FeatureVector =
new Dictionary<string, string
"Number", "5"
          GlobalParameters =
new Dictionary<string, string


Result is obtained with following line of code:

  string result = await response.Content.ReadAsStringAsync();

As a result I expect scoredLabel as boolean and scoredProbabi;ity as double. The result is encoded as a string. For example:

   Result: ["False","0.375"]

This means, for entered number 5 ML calculated the value FALSE with probability of 0.375.

If you switch not back to the ScoreModel and dig into details you will see following.


In the table above I do not see number 5, because I provided just few data. But let’s take same numbers from the list. For example number 6 and 3 and try to pass them as input in the Web Service call.

Here is the result:

For giving 6 as input I get Result: ["True","1"] and

for giving 3 as input I get Result: ["False","0.125"]

Compare these results with values in the table above and you will see that they match. This is exactly what we expected. ML Web Service returns a result which was calculated as described in the score table above.

After lot of data analysis and very complex mathematical calculations hidden behind all those shapes, we can easy publish and consume a web service from any app and device on the planet, at least theoretically.
Practically, many environments do not have access to internet. In these cases ML engine cannot be consumed. I hope the team will will nice this requirement as important one and provide us a way to download a native version of API, which can be used offline.

Related articles:
Episode I
Episode II

Posted Feb 09 2015, 08:00 AM by Damir Dobric is a .Net Community Blog powered by daenet GmbH.