Giter Site home page Giter Site logo

usrcoin-interesting / predictive-model-on-watson-ml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibm/predictive-model-on-watson-ml

0.0 1.0 0.0 17.03 MB

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

License: Apache License 2.0

JavaScript 60.40% Jupyter Notebook 36.96% CSS 1.00% HTML 1.64%

predictive-model-on-watson-ml's Introduction

DISCLAIMER: This application is used for demonstrative and illustrative purposes only and does not constitute an offering that has gone through regulatory review.

Create and deploy a scoring model to predict heart failure on IBM Cloud with the Watson Data Platform

In this Code Pattern, we will use a Jupyter Notebook on IBM Data Science Experience 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:

  • Build a predictive model within a Jupyter Notebook
  • Deploy the model to IBM Watson Machine Learning service
  • Access the Machine Learning model via either APIs or a Nodejs app

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 IBM Cloud 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.

Included components

  • IBM Data Science Experience: Analyze data using RStudio, Jupyter, and Python in a configured, collaborative environment that includes IBM value-adds, such as managed Spark.
  • Jupyter Notebook: An open source web application that allows you to create and share documents that contain live code, equations, visualizations, and explanatory text.
  • PixieDust: Provides a Python helper library for IPython Notebook.

Featured technologies

  • Artificial Intelligence: Artificial intelligence can be applied to disparate solution spaces to deliver disruptive technologies.
  • Data Science: Systems and scientific methods to analyze structured and unstructured data in order to extract knowledge and insights.
  • Node.js: An open-source JavaScript run-time environment for executing server-side JavaScript code.

Watch the Video

TBD

Steps

  1. Deploy the testing application
  2. Create an instance of the Watson Machine Learning Service
  3. Create an instance of the Data Science Experience Service
  4. Create a project in IBM Data Science Experience and bind it to your Watson Machine Learning service instance
  5. Save the credentials for your Watson Machine Learning Service
  6. Create a notebook in IBM Data Science Experience
  7. Run the notebook in IBM Data Science Experience
  8. Deploy the saved predictive model as a scoring service

Prerequisites

As of 2/5/2018, the Machine Learning service on IBM Cloud is only available in the US South or United Kingdom regions.

1. Deploy the testing application

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

Deploy to IBM Cloud

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 Data Science Experience. 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.

2. Create an instance of the Watson Machine Learning Service

  • In your browser go to the IBM Cloud Dashboard and click Catalog.

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

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

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

  • Go back to the IBM Cloud dashboard and wait until the app shows that it is running again.

3. Create an instance of the Data Science Experience Service

  • In your browser go to the IBM Cloud Dashboard and click Catalog.

  • In the navigation menu at the left, select Data & Analytics (under Platform) and then select Data Science Experience.

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

  • Click Create

4. Create a project in IBM Data Science Experience and bind it to your Watson Machine Learning service instance

  • In a new browser tab go to https://datascience.ibm.com.

  • Click on Sign In at the top of the page.

  • From the dashboard, click on New Project from the dashboard.

  • DSX projects depend on two services: Object Storage, and a Compute Engine. If you don't already have Object Storage or a Compute Engine, you can create a new instance of each service while defining a new project. The New Project panel is easy to use, either select an existing service on the right, or create a new one. In the example below services need to be created.

Note: Services created must be in the same region, and space, as your Data Science Experience service.

  • Enter Watson ML Integration as 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 Settings for the project.

  • Click on add associated service and select 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.

  • Leave the browser tab open for later.

5. Save the credentials for your Watson Machine Learning Service

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

6. Create a notebook in IBM Data Science Experience

  • 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 4. 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/IBM/predictive-model-on-watson-ml/blob/master/demo1.ipynb

  • Click Create Notebook to create the new notebook.

7. Run the notebook in IBM Data Science Experience

  • Place your cursor in the first code block in the notebook.

    Insert Spark Data Frame Step 1

  • 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 Spark Data Frame -- which is step 3 in diagram below.

Note: Make sure to rename the variable to df_data and add .option('inferSchema','True')\.

Insert Spark Data Frame Step 3

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

    Run Notebook

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

8. Deploy the saved predictive model as a scoring service

  • 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 IBM Cloud Dashboard and select the restart icon to restart the web application.

Sample Output

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

Score

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

Troubleshooting

Privacy Notice

If using the Deploy to IBM Cloud button some metrics are tracked, the following information is sent to a Deployment Tracker service on each deployment:

  • Node.js package version
  • Node.js repository URL
  • Application Name (application_name)
  • Application GUID (application_id)
  • Application instance index number (instance_index)
  • Space ID (space_id)
  • Application Version (application_version)
  • Application URIs (application_uris)
  • Labels of bound services
  • Number of instances for each bound service and associated plan information

This data is collected from the package.json file in the sample application and the VCAP_APPLICATION and VCAP_SERVICES environment variables in IBM Cloud and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Cloud to measure the usefulness of our examples, so that we can continuously improve the content we offer to you. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.

Disabling Deployment Tracking

To disable tracking, simply remove require("cf-deployment-tracker-client").track(); from the app.js file in the top level directory.

Links

Learn more

  • Artificial Intelligence Code Patterns: Enjoyed this Code Pattern? Check out our other AI Code Patterns.
  • Data Analytics Code Patterns: Enjoyed this Code Pattern? Check out our other Data Analytics Code Patterns
  • AI and Data Code Pattern Playlist: Bookmark our playlist with all of our Code Pattern videos
  • With Watson: Want to take your Watson app to the next level? Looking to utilize Watson Brand assets? Join the With Watson program to leverage exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.
  • Data Science Experience: Master the art of data science with IBM's Data Science Experience
  • Spark on IBM Cloud: Need a Spark cluster? Create up to 30 Spark executors on IBM Cloud with our Spark service

License

Apache 2.0

predictive-model-on-watson-ml's People

Contributors

justinmccoy avatar eciggaar avatar djccarew avatar scottdangelo avatar akeller avatar markstur avatar sanjay-saxena avatar stevemart avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.