Skip to content

eciggaar/watson-dojo-pm-tester

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Overview

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.

Flow

  1. The developer creates an IBM Data Science Experience Workspace.
  2. IBM Data Science Experience depends on an Apache Spark service.
  3. IBM Data Science Experience uses Cloud Object storage to manage your data.
  4. This lab is built around a Jupyter Notebook, this is where the developer will import data, train, and evaluate their model.
  5. Import data on heart failure.
  6. Trained models are deployed into production using IBM's Watson Machine Learning Service.
  7. A Node.js web app is deployed on Bluemix calling the predictive model hosted in the Watson Machine Learning Service.
  8. A user visits the web app, enters their information, and the predictive model returns a response.

Prerequisites

Before you begin

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.

Already registered and completed set-up

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.

Not registered

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.

First time login

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.

Terms & conditions

Define a name for your organization.

Organization name

Choose a name for your space. Typically dev would be a good name for your first space.

Space name

On the last page, click I'm Ready to complete the set up process.

Create a space in Bluemix US region

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.

Select US 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.

Create space in US

Step 1: Deploy the testing application

In this part of the lab you'll deploy the application that you will use later to test the predictive model that you create.

  1. Use Ctrl-click on the Deploy to Bluemix button below to open the deployment process in a separate tab.

Deploy to Bluemix

  1. Log in into Bluemix with your credentials by clicking on the Log in link at the top right.

  2. 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.

  3. Click on Deploy to deploy the application.

Deploy

  1. 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.

Toolchain

  1. Wait for the Deploy Stage to complete successfully.

Deploy Stage

Step 2: Create an instance of the Watson Machine Learning Service

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.

  1. In your browser go to the Bluemix Dashboard and click Catalog.

  2. In the navigation menu at the left, select Data & Analytics (under Platform) and then select Machine Learning.

Watson ML Service

  1. In the Connect to drop-down, select the application that you deployed earlier in Step 1 of this lab.

Connect to Service

  1. Verify this service is being created in the same space as the app in Step 1.

  2. Click Create, followed by Restage when you’re prompted to restage your application.

Connect to Service

  1. Go back to the Bluemix dashboard and wait until the app shows that it is running again.

Overview DSX services and test app

Step 3: Save the credentials for your Watson Machine Learning Service

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.

  1. Click on your Watson Machine Learning instance under Services.

Save Credentials

  1. Click on Service credentials and then on View credentials to see the credentials.

View Credentials

  1. Save the username and password to a text file on your machine. You’ll need this information later in your Jupyter notebook.

Download the sample patient data

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.

Download CSV

Congrats, you're now ready to start your data science experience 😃!!

Step 4: Sign up for IBM 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.

  1. In a web browser navigate to https://datascience.ibm.com.

  2. Click on Sign Up at the top right.

Sign Up

  1. Click on Sign in with your IBM id and enter your Bluemix credentials.

Sign In

  1. 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.

DSX dashboard

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.

  1. From the dashboard, click on Create new from the top-right. From the drop-down menu select Project.

Create New Project

  1. Enter Watson ML Integration as the project name and click Create. Leave the other settings on their default value.

  2. On the right, in the Files section, click on Browse to upload the data file you’ll use to create a predictive model.

Import Data

  1. 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).

  2. Once successfully uploaded, the file should appear in the Data Assets section.

Data Assets

  1. Click on Settings for the project.

Settings

  1. Click on add associated service and select Machine Learning.

Associate Service

  1. Choose your existing Machine Learning instance and click on Select.

Add Watson ML Service

  1. Click on your browser’s Back button and verify that the Watson Machine Learning service is now listed as one of your Associated Services.

Associated Services

  1. Leave the browser tab open for later.

Step 6: Create a notebook in IBM Data Science Experience

In this part of the lab you’ll create a Jupyter notebook and import the code to create a predictive model.

  1. 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.

Add Notebook

  1. Click on From URL and name the notebook Apache Spark integration with Watson ML.

  2. Under Notebook URL provide the following url: https://github.com/eciggaar/watson-dojo-pm-tester/blob/master/demo1.ipynb.

Create Notebook

  1. Click Create Notebook to create the new notebook.

  2. Leave your browser tab open for the next part.

Step 7: Run the notebook in IBM Data Science Experience

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.

  1. Place your cursor in the first code block in the notebook, above the existing text.

Insert Credentials Step 1

  1. 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.

Insert Credentials Step 2

  1. Your Object Storage dataframe should now be in the cell. Make sure to rename the variable to df_data. Also, paste in the option inferSchema as shown below.

Insert Credentials Step 3

  1. Click on the Run icon to run the code in the cell.

Run Notebook

  1. 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.

  2. 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.

Run Notebook

  1. Continue running each cell until you finish the entire notebook.

Step 8: Deploy the saved predictive model as a scoring service

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.

  1. In a different browser tab go to http://console.bluemix.net and log in to your dashboard.

  2. Click on the entry for your Watson Machine Learning service under Services.

  3. Click Manage and then click on the Launch Dashboard button in the Watson Machine Learning tile.

Launch Dashboard

  1. Your saved model should appear. Under Actions select Create Deployment.

Create Deployment Step 1

  1. Name the deployment Heart Failure Prediction Model Deployment and click Save. Keep the type of deployment set to the default value 'Online'.

Create Deployment Step 2

  1. Your model should now be deployed and visible as a Deployment with status 'ACTIVE'.

Create Deployment Step 3

  1. Restart the Node.js Web App. For this, return to your Bluemix Dashboard and select the restart icon to restart the web application.

Restart WebApp

Step 9: Test the deployed Model

In this part of the lab you’ll test the deployed model with the Node.js application that you deployed earlier.

  1. Click on the application URL to open the application in a separate tab.

Test Deployed Model

  1. When the application appears click on Score now to test the scoring model with the default values.

  2. Verify that the model predicts that there is a risk of heart failure for the patient with these medical characteristics.

Score

  1. Click Close. Run the app again with the following parameters.

Score

  1. Verify that the model predicts that there is not a risk of heart failure for the patient with these medical characteristics.

Score

Congratulations, you successfully created a predictive model in Apache Spark and deployed and tested it using the Watson Machine Learning Service in Bluemix 😃!!

Additional links

About

Create and deploy a predictive model using IBM Data Science Experience and Watson Machine Learning

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 87.0%
  • Jupyter Notebook 9.2%
  • HTML 2.4%
  • CSS 1.4%