Exercise 4. Getting Started With Watson Machine Learning: Estimated Time
Exercise 4. Getting Started With Watson Machine Learning: Estimated Time
Overview
This exercise introduces you to the basic tasks that you must perform while you import and deploy
machine learning models by using the Watson Machine Learning service and Watson Studio.
Objectives
After completing this exercise, you should be able to:
• Add a machine learning model saved in Predictive Model Markup Language (PMML) format to
the project.
• Deploy the machine learning model.
• Call the deployed model as a service.
• Test the machine learning model.
• Create a model by using the AutoAI graphical tool in Watson Studio.
Introduction
In this exercise, you follow the end-to-end process to import, deploy, and test a PMML machine
learning model. You also learn how to call the model that is deployed as a web service from your
applications.
PMML is the de facto standard language that is used to represent data mining models. You can
read more about PMML here. PMML stands for Predictive Model Markup Language, it is XML-
based. It allows you to easily share predictive analytic models between different applications.
Therefore, you can train a model in one system, express it in PMML, and move it to another
system where you can use it for predictions.
This exercise uses a PMML formatted model trained by using the Iris flower dataset. A similar
exercise that uses a Jupyter Notebook and is named Use PMML to predict iris species can be
found in the Watson Studio Gallery.
In the second part of this exercise, you follow a tutorial on the web to learn how to use the new
AutoAI tool in Watson Studio. You can use the AutoAI tool to build machine learning models with
your own data. AutoAI automatically detects the best model for your data. Machine learning
models that are produced by AutoAI can also be deployed and tested as any other machine
learning model in Watson Studio.
__ 7. Enter the model name, MyPMMLModel, optionally a description and click Associate a
Machine Learning service instance.
__ 8. In the Machine Learning service page, make sure that the New tab is selected, select the
Lite plan, scroll-down, and click Create.
__ 9. At the Confirm Creation prompt, accept the default values and click Confirm.
Important: You can associate a Watson Machine Learning service instance with your Watson
Studio project only when the Watson Machine Learning service instance and the Watson Studio
instance are located in the same region. Ensure that the region for both Watson Studio and
Watson Machine Learning match. If the location for the Watson Studio service instance is Dallas,
the region must be Dallas; if the location is London, the region must be London.
.
__ 12. Select From file, browse to the PMML file that you downloaded, and click Import.
__ 13. After you import the model, a summary of the model is displayed.
__ 4. Click Save.
At this point, the MyPMMLModel prediction model is deployed as a web service in IBM
Cloud.
__ 5. After the model is successfully deployed, the status changes to DEPLOY_SUCCESS as
shown in the following figure. Refresh the page if the status takes too long to change.
The following page shows the properties of the deployed web service.
For Example:
curl -X POST \
'https://iam.cloud.ibm.com/identity/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \
-d 'apikey=MlqNG80Q8Od869VGzQ9k15siFzwLJz9a8hqeWO2ZftaA'
Note: For more information about this command, see Create an IAM access token for a user or
service ID at https://cloud.ibm.com/apidocs/iam-identity-token-api#create-an-iam-access-token-for-
a-user-or-service-i
__ 5. Run the previous cURL command in Git bash. The access token is returned along with
other parameters.
Note: The auth token expires after a short time. Run the next cURL command shortly after you
retrieve the token.
Note: You can change the input values as you want to test different inputs to your model.
For Example:
curl -X POST --header 'Content-Type: application/json' --header 'Accept:
application/json' --header "Authorization: Bearer
eyJraWQiOiIyMDE5MDUxMyIsImFsZyI6IlJTMjU2In0.eyJpYW1faWQiOiJpYW0tU2VydmljZUl
kLTA4Mjc4NWJhLTRiNzItNGE4My04YmVlLWEzNDZiMGE3OTUxMCIsImlkIjoiaWFtLVNlcnZpY2
VJZC0wODI3ODViYS00YjcyLTRhODMtOGJlZS1hMzQ2YjBhNzk1MTAiLCJyZWFsbWlkIjoiaWFtI
iwiaWRlbnRpZmllciI6IlNlcnZpY2VJZC0wODI3ODViYS00YjcyLTRhODMtOGJlZS1hMzQ2YjBh
Nzk1MTAiLCJzdWIiOiJTZXJ2aWNlSWQtMDgyNzg1YmEtNGI3Mi00YTgzLThiZWUtYTM0NmIwYTc
5NTEwIiwic3ViX3R5cGUiOiJTZXJ2aWNlSWQiLCJhY2NvdW50Ijp7InZhbGlkIjp0cnVlLCJic3
MiOiIxYmZjNzlkMWU0Mzk0NDRmYTkwNjU2MWFjNDdkNTEwNSJ9LCJpYXQiOjE1NjY5ODI2NjgsI
mV4cCI6MTU2Njk4NjI2OCwiaXNzIjoiaHR0cHM6Ly9pYW0uYmx1ZW1peC5uZXQvaWRlbnRpdHki
LCJncmFudF90eXBlIjoidXJuOmlibTpwYXJhbXM6b2F1dGg6Z3JhbnQtdHlwZTphcGlrZXkiLCJ
zY29wZSI6ImlibSBvcGVuaWQiLCJjbGllbnRfaWQiOiJkZWZhdWx0IiwiYWNyIjoxLCJhbXIiOl
sicHdkIl19.IxJqDWVx-XFMJC_078Gz1ye69LtD6f6JCHQdDo-8AIajIaA_bVg-
Q5HiB94_5Q35AMy2j9B3-
2O097FwJOVD1v1vXTeLFodAGTXghUF3tK1rEVOP3dx21yy8JlYqAx6RR3xyo-
O3BtawU76YoFUfN66im6IPBAr6V43X4dLGnGGxNexJLbPSehPPZehI4DyvQ5f7K3Eo3e5ltPcMc
fLFtKTjP1Aqfxz-
TcC1QjFLx2LBPbv53TIRTQWnF1v6vBxxxfEiNQyCY_YJ6WkRWEfrvd9rfUfAMI80As2Ufe-
1lJdxG3EiXgv_b0pgWxBpFLx1Kp7O3_wukrhwxoCXprMxvg" --header "ML-Instance-ID:
3d24c49a-c471-40b3-a592-d85feb73f13a" -d '{"fields": ["Petal.Width",
"Sepal.Width", "Petal.Length"],"values": [[0.2, 3.5, 1.4]]}' https://us-
south.ml.cloud.ibm.com/v3/wml_instances/3d24c49a-c471-40b3-a592-
d85feb73f13a/deployments/b9d608c6-2b64-445e-a7e8-c0881c63387c/online
__ 9. The score results for the array of input values are returned:
__ 10. In the deployment page, click View API Specification to display the API information.
__ 11. Browse through the web page IBM Watson Machine Learning API to the review the API
documentation.
The test results show that a flower with these features is more likely to be Iris-Setosa. View the
iris-dataset in the Gallery page by searching for “Iris” and test several values from the dataset.
__ 2. Change the input data to test different predictions and view the results.
Part 2. Creating a machine learning model with IBM Watson Studio and
the AutoAI tool
The AutoAI graphical tool in Watson Studio automatically analyzes your data and generates
candidate model pipelines that are customized for your predictive modeling problem. These model
pipelines are created over time as AutoAI algorithms learn more about your dataset and discover
data transformations, estimator algorithms, and parameter settings that work best for your problem
In this part, follow the tutorial AutoAI tutorial: Build a binary classification model. This tutorial
guides you through training a model to predict whether a customer is likely to buy a tent from an
outdoor equipment store. In this tutorial, you create an AutoAI experiment in IBM Watson Studio to
build a model. This model analyzes your data and selects the best model type and algorithms to
produce, train, and optimize pipelines, which are model candidates. After you review the pipelines,
you save one as a model, deploy it, and then test it to get a prediction.
End of exercise