This sample application demonstrates the IBM Watson Machine Learning Bluemix offering. It's an extension of the Big Data University Predicting Customer Satisfaction course. While participation in the course is recommended, it's not required.
This application is based on the Node.js and Express framework. It uses the Machine Learning service API for IBM SPSS Modeler models to integrate with IBM SPSS Modeler analytics.
With this sample scoring application, you can:
- Select one of the IBM SPSS Modeler streams uploaded to the Watson Machine Learning service on Bluemix
- Specify which source node should be used as the scoring input
- Verify the required input data schema (field name and type)
- Drag-and-drop a csv file that contains input data for scoring (or double-click an input data field to open the file browser)
- Click the Get Score button to call the Watson Machine Learning service scoring API
- Display the scoring results table
- IBM ID to log in to Bluemix. See free trial if you don't yet have an ID.
- Cloud Foundry command line interface (only if you want to manually deploy to Bluemix)
- IBM SPSS Modeler (only if you want to modify streams or create new ones; see Preparing the SPSS Modeler stream for details)
- Node.js runtime (only if you want to modify the source code)
The general, high-level steps are described below. Refer to IBM Watson Machine Learning Service for Bluemix - General for complete details.
- From the Bluemix catalog, choose the Watson Machine Learning service. This service will later bind to a Node.js application created from this sample. From this point, note that the service itself offers a set of samples (this particular one among them) that can be automatically deployed and bound, which is the simplest way to see the sample in action.
- Upload an SPSS Modeler stream file to your instance of the Watson Machine Learning service (the classic service with SPSS streams). This sample application comes with an SPSS Modeler stream (stream/customer-satisfaction-prediction.str) that can be used for this purpose.
For a fast start, you can deploy the prebuilt app to Bluemix by clicking the following button:
Note that the application is fully functional only if bound to an instance of the Watson Machine Learning service, which must be done manually. See instructions.
As an alternative to the button, you can manually deploy the application to Bluemix by pushing it with Cloud Foundry commands, as described in the next section. Manual deployment is required when you want to deploy modified source code. Manual deployment consists of pushing the application to Bluemix followed by binding the Watson Machine Learning service to the deployed application.
To push an application to Bluemix, open a shell, change to the directory of your application, and run the following:
cf api <region>
where <region> part may be https://api.ng.bluemix.net or https://api.eu-gb.bluemix.net depending on the Bluemix region you want to work with (US or Europe, respectively)cf login
which is interactive; provide all required datacf push <app-name>
where <app-name> is the application name of your choice
cf push
can also read the manifest file (see Cloud Foundry Documentation). If you decide to use the manifest, you can hardcode the name of your instance of the Watson Machine Learning service instead of binding it manually. See the services section of the manifest.yml.template file.
If this is your first Bluemix Node.js application, see the node-helloworld project documentation to gain general experience.
See the instructions.
Running the application locally is useful when you want to test your changes before deploying them to Bluemix. For information about working with source code, see Source code changes.
When the changes are ready, open a shell, change the directory to your cloned repository, and run npm start
to start the application. The running application is available in a browser at http://localhost:6001.
Applications that run locally can also use the Watson Machine Learning service. See the instructions.
The repository comes with a prebuilt application. If you want to rebuild the app after modifying the sources:
- Follow the steps listed in the Requirements section
- Change to the directory containing the downloaded source code or the cloned git repo
- Run
npm install
- Run
./node_modules/.bin/webpack
To add the power of IBM SPSS Modeler analytics to any application, use the Watson Machine Learning service API.
The source code placed in the pm_client.js file provides an example of how to call this service API through JavaScript code. It demonstrates the following aspects:
- Retrieval of all currently deployed models
- Metadata retrieval for a chosen predictive model
- Scoring with a chosen predictive model
As stated in the Requirements section, from the Bluemix catalog you must order an instance of the Watson Machine Learning service if you don't yet have one. The next step is to connect your deployed application to the service, which is called binding. There are a few ways to achieve this in the Bluemix environment. This documentation describes binding either via the Bluemix user interface or by using cf cli.
- Deploy the application to Bluemix and bind it to the Watson Machine Learning service.
- Go to the application overview pane, choose the bound Watson Machine Learning service, and click Show Credentials. Copy the pm-20 credentials json portion (url, access_key).
- Create the ./config/local.json file by copying the ./config/local.json.template file. Edit the local.json file and paste the pm-20 credentials you obtained in the previous step.
- Start your local application. You should now be able to interact with the Watson Machine Learning service (for example, by listing the uploaded models).
The IBM SPSS Modeler stream file customer-satisfaction-prediction.str is included with this sample application. The file is located in the stream subdirectory. The scoring branch (highlighted in green) is the trained predictive model (Support Vector Machine with RBF kernel).
The stream requires input data on the source node when making a scoring request, as shown below. The sample input data file scoreInput.csv is in the data subdirectory.
The scoring request result is represented by the Output data Table node. The predicted churn and probability of churn are represented by the Predicted Churn and Probability of Churn fields defined in the Table node.
The code is available under the Apache License, Version 2.0.