Name: predictive-model-on-watson-ml
Owner: International Business Machines
Description: Create and deploy a predictive model using Watson Studio and Watson Machine Learning
Forked from: djccarew/watson-dojo-pm-tester
Created: 2017-08-22 15:36:28.0
Updated: 2018-05-21 20:29:04.0
Pushed: 2018-05-21 20:29:03.0
Size: 18359
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
DISCLAIMER: This application is used for demonstrative and illustrative purposes only and does not constitute an offering that has gone through regulatory review.
Data Science Experience is now Watson Studio. Although some images in this code pattern may show the service as Data Science Experience, the steps and processes will still work.
In this Code Pattern, we will use a Jupyter Notebook on IBM Watson Studio to build a predictive model that demonstrates a potential health care use case. This a customized version of the Node.js sample app that is available with the Watson Machine Learning Service on IBM Cloud. See the original app for a walkthrough of the source code.
When the reader has completed this Code Pattern, they will understand how to:
An account on IBM Watson Studio.
A space in IBM Cloud US South or United Kingdom regions.
As of 2/5/2018, the Machine Learning service on IBM Cloud is only available in the US South or United Kingdom regions.
Use Ctrl-click on the Deploy to IBM Cloud
button below to open the deployment process in a separate tab.
Note: Make sure to deploy the application to the same region and space as where the Apache Spark and Cloud Object Storage services were created when you signed up for IBM Watson Studio. 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 IBM Cloud. Click on the Delivery Pipeline tile to see the status of the deployment. Wait for the Deploy Stage to complete successfully.
In your browser go to the IBM Cloud Dashboard and click Catalog
.
Search for Machine Learning
, Verify this service is being created in the same space as the app in Step 1, and click Create
.
On the Watson ML Dashboard select Connections
on left menu panel, and Create Connection
. Select the application that you deployed earlier in Step 1 of this lab connecting this Watson ML service to the Cloud Foundry application deployed.
Click Restage
when you?re prompted to restage your application. The app will take a couple of minutes to be back in the running
state.
In your browser go to the IBM Cloud Dashboard, click Catalog
, and search for Watson Studio
. Verify this service is being created in the same space as the app in Step 2, and click Create
.
Create a new project by clicking + New project
and choosing Data Science
:
Note: Services created must be in the same region, and space, as your Watson Studio service. Note: If this is your first project in Watson Studio, an object storage instance will be created.
Enter a name for the project name and click Create
.
From within the new project Overview
panel, click Add to project
on the top right, selecting Data asset
.
A panel on the right of the screen appears, select load
and click on Browse
to upload the data file you'll use to create a predictive model.
On your machine, browse to the location of the file patientdataV6.csv in this repository in the data/ directory. 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 the Settings
tab for the project, scroll down to Associated services
and click + Add service
-> Machine Learning
.
Choose your existing Machine Learning instance and click on Select
.
The Watson Machine Learning service is now listed as one of your Associated Services
.
Click on the Settings
tab for the project, scroll down to Associated services
and click + Add service
-> Spark
.
Either choose and Existing
Spark service, or create a New
one
Leave the browser tab open for later.
In a different browser tab go to http://console.bluemix.net and log in to the Dashboard.
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, password and instance_id to a text file on your machine. You?ll need this information later in your Jupyter notebook.
In Watson Studio using the project you've created, click on + Add to project
-> Notebook
OR in the Assets
tab under Notebooks
choose + New notebook
to create a notebook.
Select the From URL
tab.
Enter a name for the notebook.
Optionally, enter a description for the notebook.
Under Notebook URL
provide the following url: https://github.com/IBM/predictive-model-on-watson-ml/blob/master/demo1.ipynb
Select the Spark runtime.
Click the Create
button.
Place your cursor in the first code block in the notebook.
Click on the Find and Add
data icon – see step 1 in diagram below – and then select Insert to code
under the file patientdataV6.csv. This is step 2 in diagram below. Finally select Insert SparkSession Data Frame
– which is step 3 in diagram below.
Note: Make sure to rename the variable to
df_data
and add.option('inferSchema','True')\
.
Goto the cell that says Stop here !!!!
during Step 5, insert the username and password that you saved from your Watson Machine Learning instance into the code before running it. Do the same after Step 6 Save model to WML Service
.
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.
In Watson Studio](https://dataplatform.ibm.com) go to you project, under Assets
-> Models
and click on the model you've created: Heart Failure Prediction Model
.
Go to the Deployments
tab and + Add Deployment
.
Give your Deployment a name, click Create
, and it should show up with STATUS
of DEPLOY_SUCCESS
.
Restart the Node.js Web App. For this, return to your IBM Cloud Dashboard, choose your application, and select restart from the More action
three vertical dots
instance_id
from yout Watson Machine Learning Service credentials.
During Step 6.2, after running the second cell, get the model_id
and put it in the cell that follows.
Put the deployment_id
in the cell under Montitor the status of deployment
.
For Step 6.3, add the scoring_url
to the cell.Visit App URL
from the Overview
page 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.