| copyright |
|
||
|---|---|---|---|
| lastupdated | 2017-11-16 |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen: .screen} {:codeblock: .codeblock} {:pre: .pre}
To use {{site.data.keyword.pm_full}}, you must be able to create the proper machine learning environment and retrieve the credentials that are specific to that environment. You can create the {{site.data.keyword.Bluemix_full}} instance either by using the Cloud Foundry command line interface or through the graphical user interface in the {{site.data.keyword.Bluemix_full}} Dashboard. {: shortdesc}
To use {{site.data.keyword.pm_full}}, you must create an instance of it in your {{site.data.keyword.Bluemix_notm}} Dashboard.
Depending on your scenario, you may also need the following resources:
- Object Storage (batch deployment)
- Db2 Warehouse on Cloud (batch deployment)
- Apache Spark (batch, stream deployment and continuous learning system)
- Message Hub (stream deployment)
To see how to work with the Dashboard to create the {{site.data.keyword.Bluemix_notm}} instances and view credentials, watch the following video, which supplements the written steps, which follow the video.
<iframe width="560" height="315" src="https://www.youtube.com/embed/fm8gqguFD9g?rel=0" frameborder="0" allowfullscreen></iframe>To create the {{site.data.keyword.pm_full}} instance, you must perform the following steps:
- Open the {{site.data.keyword.pm_full}} service page
- Sign up or log in to create the service instance.
- Enter a descriptive name for your instance, choose a space, and select your data plan.
- Click Create Instance.
Your instance opens.
To use your {{site.data.keyword.Bluemix_notm}} (previously known as Bluemix) instance, you need service instance credentials. You can create and access your credentials either through the CF CLI or the {{site.data.keyword.Bluemix_notm}} Dashboard. After you bind the {{site.data.keyword.pm_short}} service instance to your {{site.data.keyword.Bluemix_notm}} application, the {{site.data.keyword.pm_short}} credentials are added to the VCAP_SERVICES environment variable. For more information, see using the service with application.
To retrieve {{site.data.keyword.pm_full}} instance credentials, you must perform the following steps:
- Log in to {{site.data.keyword.Bluemix_notm}}.
- From the Services section, click the service name whose credentials you want to retrieve.
- In the navigation pane, click Service credentials.
- In the list of credentials, click View credentials.
- If no credentials exist for this service, create them by clicking Create credentials.
- To copy the credentials, click the copy icon.
To use the {{site.data.keyword.pm_short}} service in your application, you must bind the service to the {{site.data.keyword.Bluemix_notm}} application and the necessary credentials to run the application are inserted into the VCAP_SERVICES environmental variable. For more information, see Cloud Foundry command line interface.
You can download Node.js sample code to try the Machine Learning service. Complete the following steps to create your {{site.data.keyword.Bluemix_notm}} application and bind the {{site.data.keyword.pm_short}} service. These examples use Node.js because it is a popular runtime. Others can be used such as iOS, Ruby, Perl, or Java.
You can also perform steps 1 - 3 by using the {{site.data.keyword.Bluemix_notm}} Graphical Interface instead of the Cloud Foundry tool (cf).
-
Use the
cf create-servicecommand to create a service instance:cf create-service pm-20 lite {local naming}{: codeblock}
For example, the following command creates one {{site.data.keyword.pm_short}} service instance with the lite plan named
my_wml_litein your {{site.data.keyword.Bluemix_notm}} space:cf create-service pm-20 lite my_wml_lite{: codeblock}
-
Use the
cf create-service-keycommand to create service credentials:cf create-service-key "{service instance name}" {vcap key name}{: codeblock}
For example, the following command creates {{site.data.keyword.pm_short}} service credentials:
cf create-service-key "IBM {{site.data.keyword.pm_full}} - my instance" Credentials-1{: codeblock}
-
Use the
cf bind-servicecommand to bind the service instancemy_wml_liteto your application.cf bind-service {AppName} my_wml_lite{: codeblock}
For example, the following command binds the {{site.data.keyword.pm_short}} service instance
my_wml_liteto the {{site.data.keyword.Bluemix_notm}} applicationmy_app1:cf bind-service my_app1 my_wml_lite{: codeblock}
After you bind the {{site.data.keyword.pm_short}} service instance to your {{site.data.keyword.Bluemix}} application, the {{site.data.keyword.pm_short}} credentials are added to the VCAP_SERVICES environment variable:
{
"pm-20-dev": [
{
"credentials": {
"url":
"https://ibm-watson-ml.mybluemix.net",
"access_key": "**********",
"username": "**********",
"password": "**********",
"instance_id": "**********"
},
"label": "pm-20-dev",
"plan": "lite",
"name": "IBM Watson Machine Learning”
}
]
}
{: codeblock}
The VCAP_SERVICES environment variable includes the following
information:
- plan
- the {{site.data.keyword.pm_short}} plan that is used in the service provisioning.
- url
- the address of the {{site.data.keyword.pm_short}} service instance.
- access_key
- for IBM® SPSS® Modeler streams only.
- instance_id
- {{site.data.keyword.pm_short}} instance unique identifier.
- username
- the user name, which is part of the basic authorization that is needed to generate an access token to pass in all requests to this service instance.
- password
- the password, which is part of the basic authorization that is needed to generate an access token to pass in all requests to this service instance.
For example, you can generate an access token by using the following curl command:
Request example:
curl --basic --user {username}:{password} https://ibm-watson-ml.mybluemix.net/v3/identity/token
Output example:
{"token":"**********"}
{: codeblock}
The following Node.js code is an example of how to obtain the
username and password values from the VCAP_SERVICES environment
variable:
if (process.env.VCAP_SERVICES) {
var env = JSON.parse(process.env.VCAP_SERVICES);
var credentials = env['pm-20'][0].credentials;
var username = credentials.username;
var password = credentials.password;
var instance_id = credentials.instance_id;
}
{: codeblock}