This a customized version of the Node.js sample app that is available with the Watson Machine Learning Service on IBM Bluemix. This version of the app is to be used with the Data Science Experience Service to test a predictive model developed in the lab.
See the original app for a walkthrough of the source code.
Lab - Create and deploy a scoring model to predict heart failure w/Bluemix and IBM Data Science Experience
© Copyright IBM Corporation 2017
IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.
This document is current as of the initial date of publication and may be changed by IBM at any time.
The information contained in these materials is provided for informational purposes only, and is provided AS IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, these materials. Nothing contained in these materials is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. References in these materials to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. This information is based on current IBM product plans and strategy, which are subject to change by IBM without notice. Product release dates and/or capabilities referenced in these materials may change at any time at IBM's sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way.
This lab is designed to demonstrate how to use IBM Data Science Experience to build a predictive model within a Jupyter Notebook. The predictive model is then deployed to the Watson Machine Learning Service in Bluemix where it is consumed by users accessing a Node.js application.
- The developer creates an IBM Data Science Experience Workspace.
- IBM Data Science Experience depends on an Apache Spark service.
- IBM Data Science Experience uses Cloud Object storage to manage your data.
- This lab is built around a Jupyter Notebook, this is where the developer will import data, train, and evaluate their model.
- Import data on heart failure.
- Trained models are deployed into production using IBM's Watson Machine Learning Service.
- A Node.js web app is deployed on Bluemix calling the predictive model hosted in the Watson Machine Learning Service.
- A user visits the web app, enters their information, and the predictive model returns a response.
- Bluemix supported web browser
- An IBM Bluemix Account
To be able do this lab a Bluemix account is necessary. If you don't have one yet -- or you did not complete the initial set up of your Bluemix account -- follow the steps below.
Your account must have enough resources available for at least 1 application (128MB) and 5 services.
When you already registered and completed the initial set-up of your Bluemix account, you directly jump to Create a space in Bluemix US region.
Use Ctrl-click (or the equivalent action for your system) to open the Sign Up for Bluemix page in a separate tab. Fill in the form and click Create Account to complete the registration. You will receive an activation mail in your inbox.
Use Ctrl-click (or the equivalent action for your system) to open the Login to Bluemix in a separate tab. First time users need to complete a 4-step wizard. This starts by accepting the terms & conditions.
Define a name for your organization.
Choose a name for your space. Typically dev
would be a good name for your first space.
On the last page, click I'm Ready to complete the set up process.
For the remainder of this lab we switch to the US region of Bluemix. For this, use Ctrl-click (or the equivalent for your system) to open the Bluemix dashboard. Click your account and choose US South as your active region.
If you are all OK, you get the dashboard. Otherwise, you will be asked to create your first space in this region -- as depicted in the screenshot below. Typically dev
would be a good name for your space.
In this part of the lab you'll deploy the application that you will use later to test the predictive model that you create.
- Use Ctrl-click on the Deploy to Bluemix button below to open the deployment process in a separate tab.
-
Log in into Bluemix with your credentials by clicking on the Log in link at the top right.
-
Make sure to deploy the application to the US South region and space you created above. Please take note of this space as later in this lab the Watson Machine Learning service needs to be deployed into the same space.
-
Click on Deploy to deploy the application.
- A Toolchain and Delivery Pipeline will be created for you to pull the app out of Github and deploy it in to Bluemix. Click on the Delivery Pipeline tile to see the status of the deployment.
- Wait for the Deploy Stage to complete successfully.
In this part of the lab, you'll create an instance of the Watson Machine Learning service and bind it to the application that you created in Step 1.
-
In your browser go to the Bluemix Dashboard and click Catalog.
-
In the navigation menu at the left, select Data & Analytics (under Platform) and then select Machine Learning.
- In the Connect to drop-down, select the application that you deployed earlier in Step 1 of this lab.
-
Verify this service is being created in the same space as the app in Step 1.
-
Click Create, followed by Restage when you’re prompted to restage your application.
- Go back to the Bluemix dashboard and wait until the app shows that it is running again.
In this part of the lab you’ll save the credentials for your Watson Machine Learning instance so you can use it later in your code.
- Click on your Watson Machine Learning instance under Services.
- Click on Service credentials and then on View credentials to see the credentials.
- Save the username and password to a text file on your machine. You’ll need this information later in your Jupyter notebook.
Use Ctrl-click (or the equivalent action for your system) to open the patientdataV6.csv CSV file in a separate tab. Click Download to download this file to your own device.
Congrats, you're now ready to start your data science experience 😃!!
IBM Data Science Experience is an interactive, collaborative, cloud-based environment where data scientists can use multiple tools to activate their insights. In this part of the lab you will sign up for a 30-day trial of IBM Data Science Experience.
-
In a web browser navigate to https://datascience.ibm.com.
-
Click on Sign Up at the top right.
- Click on Sign in with your IBM id and enter your Bluemix credentials.
- Follow the instructions to complete the sign up for IBM Data Science Experience. Note that three Bluemix services will be created for you -- a Cloud Object Storage service, an Apache Spark service and a Data Science Experience service. As soon as the 'Get Started' button is clickable, click it and you should be directed to the Data Science Experience dashboard as shown below.
Step 5: Create a project in IBM Data Science Experience and bind it to your Watson Machine Learning service instance
In this part of the lab you will create a new project in IBM Data Science Experience and bind it to your instance of the Watson Machine Learning service.
- From the dashboard, click on Create new from the top-right. From the drop-down menu select Project.
-
Enter Watson ML Integration as the project name and click Create. Leave the other settings on their default value.
-
On the right, in the Files section, click on Browse to upload the data file you’ll use to create a predictive model.
-
On your laptop, browse to the location where you downloaded the file patientdataV6.csv in the section Download patient data of this lab. Select the file and click on Open (or the equivalent action for your operating system).
-
Once successfully uploaded, the file should appear in the Data Assets section.
- Click on Settings for the project.
- Click on add associated service and select Machine Learning.
- Choose your existing Machine Learning instance and click on Select.
- Click on your browser’s Back button and verify that the Watson Machine Learning service is now listed as one of your Associated Services.
- Leave the browser tab open for later.
In this part of the lab you’ll create a Jupyter notebook and import the code to create a predictive model.
- If you don't have your newly created Project open, first click Projects -> View All Projects, and then select your newly created project from Step 5. Next, in the Data Science Experience browser tab click on Overview and then click add notebooks.
-
Click on From URL and name the notebook Apache Spark integration with Watson ML.
-
Under Notebook URL provide the following url: https://github.com/eciggaar/watson-dojo-pm-tester/blob/master/demo1.ipynb.
-
Click Create Notebook to create the new notebook.
-
Leave your browser tab open for the next part.
In this part of the lab you will run the Jupyter Notebook code creating a predictive model, and save it in the Watson Machine Learning Service.
- Place your cursor in the first code block in the notebook, above the existing text.
- Click on the Find and Add data icon and then select Insert to code under the file patientdataV6.csv. Finally select Insert SparkSession DataFrame -- as shown in the diagram.
- Your Object Storage dataframe should now be in the cell. Make sure to rename the variable to
df_data
. Also, paste in the optioninferSchema
as shown below.
- Click on the Run icon to run the code in the cell.
-
Move your cursor to each code cell and run the code in it. Read the comments for each cell to understand what the code is doing. Important when the code in a cell is still running, the label to the left changes to In [*]:. Do not continue to the next cell until the code is finished running.
-
When you get to the cell that says Stop here !!!! insert the username and password that you saved from your Watson Machine Learning instance into the code before running it.
- Continue running each cell until you finish the entire notebook.
In this part of the lab you’ll deploy the model you saved by running the Python notebook as a scoring service in Watson Machine Learning.
-
In a different browser tab go to http://console.bluemix.net and log in to your dashboard.
-
Click on the entry for your Watson Machine Learning service under Services.
-
Click Manage and then click on the Launch Dashboard button in the Watson Machine Learning tile.
- Your saved model should appear. Under Actions select Create Deployment.
- Name the deployment Heart Failure Prediction Model Deployment and click Save. Keep the type of deployment set to the default value 'Online'.
- Your model should now be deployed and visible as a Deployment with status 'ACTIVE'.
- Restart the Node.js Web App. For this, return to your Bluemix Dashboard and select the restart icon to restart the web application.
In this part of the lab you’ll test the deployed model with the Node.js application that you deployed earlier.
- Click on the application URL to open the application in a separate tab.
-
When the application appears click on Score now to test the scoring model with the default values.
-
Verify that the model predicts that there is a risk of heart failure for the patient with these medical characteristics.
- Click Close. Run the app again with the following parameters.
- Verify that the model predicts that there is not a risk of heart failure for the patient with these medical characteristics.
Congratulations, you successfully created a predictive model in Apache Spark and deployed and tested it using the Watson Machine Learning Service in Bluemix 😃!!
- More data science journeys on IBM Code: https://developer.ibm.com/code/journey/category/data-science/
- IBM Data Science Experience: https://www.ibm.com/analytics/us/en/watson-data-platform/data-science-experience/
- Watson Data Platform: https://www.ibm.com/analytics/us/en/watson-data-platform/