Coder Social home page Coder Social logo

eduardomoraesritter / chatbot-using-predictive-analysis-with-wml-heart-failure Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sergiogama/chatbot-using-predictive-analysis-with-wml-heart-failure

1.0 1.0 0.0 13.35 MB

This tutorial uses Watson Studio and Modeller Flow to make a predictive analysis model to be used on Watson Machine Learning. This model will be integrated in a ChatBot on Watson Assistant, thru IBM Cloud Functions (Serverless)

License: Apache License 2.0

JavaScript 73.61% CSS 21.45% HTML 4.94%

chatbot-using-predictive-analysis-with-wml-heart-failure's Introduction

TUTORIAL: Develop a virtual assistant for health to predict heart failure using neural network on Modeller Flow in Watson Studio, via Watson Machine Learning, connected to Watson Assistant thru an action on Cloud Functions

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

This tutorial can be thought of as 4 distinct parts:

  1. A predictive model will be built using Modeller Flow on IBM Watson Studio. The model is deployed to the Watson Machine Learning service, where it can be accessed via a REST API.

  2. A action developed on IBM Cloud Functions in Node.js to connect to WML service to be scored against the previous model.

  3. A ChatBot on Watson Assistant to collect the user / patient information to be socred against the previous model, thru integration on IBM Cloud Functions.

  4. Node.js app to interact to ChatBot to collect data and give the prediction of Heart Failure to the user.

When the reader has completed this tutorial, they will understand how to:

  • Build a predictive model within a Modeller Flow on Watson Studio
  • Deploy the model to the IBM Watson Machine Learning service
  • Create a action on IBM Cloud to call WML service
  • Deploy a Chatbot on Watson Studio and integrate it to Cloud Functions
  • Via a Node.js app, score some data against the model via an API call to the Watson Machine Learning service

Sample output

Here's an example of what the final web app looks like

form

Architecture

  1. The developer creates an IBM Watson Studio Workspace.
  2. IBM Watson Studio uses an Apache Spark service.
  3. IBM Watson Studio uses Cloud Object storage to manage your data.
  4. IBM Watson Studio uses a Modeller Flow to import data, train, and evaluate their model.
  5. Data is imported and stored on Cloud Object Storage.
  6. Models trained via Modeller Flow are deployed using the Watson Machine Learning service.
  7. The developer creates an Node.js Action on IBM Cloud Functions to call WML service (API)
  8. The developer create Watson Assistant to deploy a chatbot
  9. Watson Assistant call the action on IBM Cloud Functions, send data collect as parameters.
  10. A Node.js web app is deployed on IBM Cloud, it connects Watson AssistantLearning service.
  11. A user visits the web app, enters their information, and the predictive model returns a response.

"architecture diagram"

Included components

  • IBM Watson Studio: Analyze data using RStudio, Jupyter, and Python in a configured, collaborative environment that includes IBM value-adds, such as managed Spark.
  • Modeller Flow: With SPSS Modeler flows in Watson Studio, you can quickly develop predictive models using business expertise and deploy them into business operations to improve decision making.
  • Watson Machine Learning: Watson Machine Learning helps enable organizations to harness machine learning, deep learning and decision optimization to deliver business value.
  • IBM Cloud Functions: Run your application code without servers, scale it automatically, and pay nothing when it's not in use.
  • Watson Assistant: Watson Assistant is an offering for building conversational interfaces into any application, device, or channel.
  • Node.js: An open-source JavaScript run-time environment for executing server-side JavaScript code.

Prerequisites

NOTE: N/A.

Steps

  1. Setup project and data in Watson Studio
  2. Create and deploy a predictive model with Watson Studio
  3. The client side

1. Setup project and data in Watson Studio

To complete this tutorial we'll need to do a few setup steps before creating our model. In Watson Studio we need to: create a project, add our patient data (which our model will be based on), upload our notebook, and provision a Watson Machine Learning service.

1.1. Create a project in Watson Studio

  • Log into IBM's Watson Studio. Once in, you'll land on the dashboard.

  • Create a new project by clicking + Crete a project and choosing Create an empty project:

    studio project

  • Enter a name for the project name and click Create.

NOTE: By creating a project in Watson Studio a free tier Object Storage service will be created in your IBM Cloud account. Select the Free storage type to avoid fees.

1.2 Add patient data as an asset

The data used in this example was generated using a normal distribution. Attributes such as age, gender, heartrate, minutes of exercise per week, and cholesterol are used to create the model we will eventually deploy.

  • From the new project Overview panel, click + Add to project on the top right and choose the Data asset type.

    add asset

  • A panel on the right of the screen will appear to assit you in uploading data. Follow the numbered steps in the image below.

    • Ensure you're on the Load tab. [1]
    • Click on the browse option. From your machine, browse to the location of the patientdataV6.csv file in this repository, and upload it. [not numbered]
    • Once uploaded, go to the Files tab. [2]
    • Ensure the patientdataV6.csv appears. [3]

    add patient data

  • TIP: Once successfully uploaded, the file should appear in the Data assets section of the Assets tab.

    data asset

1.3 Provision a Watson Machine Learning service

  • Click on the navigation menu on the left () to show additional options. Click on the Watson Services option.

    add asset

  • From the overview page, click + Add service on the top right and choose the Machine Learning service. Select the Lite plan to avoid fees.

  • Once provisioned, you should see the service listed in the Watson Services overview page. Select the service by opening the link in a new tab. We're now in the IBM Cloud tool, where we will create service credentials for our now Watson Machine Learning service. Follow the numbered steps in the image below. We'll be using these credentials in Step 2, so keep them handy!.

    wml credentials

  • TIP: You can now go back the project via the navigation menu on the left ().

    add asset

1.4 Create a Modeller Flow in Watson Studio

A completed version can be found in [model/Heart Failure Prediction.str](model/Heart Failure Prediction.str).

  • From the new project Overview panel, click + Add to project on the top right and choose the Modeller Flow asset type. Fill in the following information:

    • Select the New tab. [1]
    • Enter a Name for the flow and optionally a description. [2]
    • Under Select flow type choose Modeller flow, and under Run time choose IBM SPSS Modeller
    • Click Create

    add notebook

  • TIP: Once successfully created, the modeller flow should open the flow editor.

    notebook asset

2. Create and deploy a predictive model with Watson Studio

Now that we're in our Modeller Flow editor, we can start to create our predictive model by stepping through the notebook.

modeller flow viewer

2.1 Start stepping through the Modeller Flow

  • Open Import tab in the left side and drag and drop Data asset node to the flow area.
  • Double click on Data asset node and click on Change data asset in the right pane.
  • Click on Data Asset, and then patientdataV6.csv, and click Ok

data asset

  • Open Fields operations tab in the left side and drag and drop Type node to the flow area.

  • Connect Data asset node to Type.

  • Drag and drop Partition node to the flow area.

  • Double click on Partition node and configure Training partion(%) to 75, and Testing partition(%) to 25, and click Save.

  • Open Modelingtab in the left side and drag and drop Neural netnode to the flow data.

  • Double click on Neural net node and check Use custom fields roles, then under Inputs area click on Add columns, uncheck HEARTFAILURE, and click Ok.

  • Under Targets area click on Add columns, mark the field HEARTFAILURE. Click Okand then Save

  • Run the model - Click on run button on top os screen.

    modeller flow viewer

2.2 Deploy the model

  • Now let's run Step 6 of the notebook. Deploy our model so we can have an endpoint to score data against.

    score-url-in-nb

Now that we have an API, let's create a client side interface that a typical user would interact with.

3. The client side

3.1 Deploy the web app

You can deploy this application as a Cloud Foundry application to IBM Cloud by simply clicking the button below. This option will create a deployment pipeline, complete with a hosted Git lab project and devops toolchain.

Deploy to IBM Cloud

  • You may be prompted for an IBM Cloud API Key during this process. Use the Create (+) button to auto-fill this field and the others.

    pipeline

  • Click on the Deploy button to deploy the application.

  • You can view the URL where the app will live by either waiting for the deployment to finish, or by finding your app from the IBM Cloud dashboard. or Click on the application name, then choose Visit App URL from the Overview page to open the application in a separate tab.

    open app

3.2 Bind the app with the existing Maching Learning service

  • From the application's overview page, select the Connections option from the left menu panel. This will allow us to associate our Watson Machine Learning service with the application. Find the Watson Machine Learning service (likely prefixed with pm-20), click the Connect button, and choose the default options for the IAM generated credentials. and select the Watson Machine Learning service you provisioned earlier.

    connect app

  • When prompted to restage your application click the Restage button. The app will take a couple of minutes to come back online. Refresh any web pages that have the app running.

Why do this? The application is expecting information about the Maching Learning service via environment variables. By associating the application with the service, details about the service, such as the deployment id, and other sensitive information are accessible through environment variables.

3.3 Interacting with the web app

The app is fairly self-explantory, simply fill in the data you want to score and click on the Score now button to test how those figures would score against our model.

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

    risk

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

    no risk

License

This tutorial is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this tutorial are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

chatbot-using-predictive-analysis-with-wml-heart-failure's People

Contributors

sergiogama avatar

Stargazers

 avatar

Watchers

 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.