Search This Blog

Friday, June 2, 2017

IBM Watson Cognitive app using Machine learning service

 

Cognitive App building with IBM Watson machine learning service.

Recently I have been hearing a lot of noise on cognitive and machine learning so I thought of giving it a try.

The hunt started with making a cognitive app which can learn from the old data and can use prediction service(Now IBM Machine learning) to give a prediction score for the current data.

 

Lets get started and build a Node JS app which can make real time prediction on IBM IOT watson platform and uses node red for real time predictions.

 

How to make an App and use the IBM Machine learning service

  • Getting the data
  • Installing IBM SPSS modeler tool
  • Finding and creating the right model
  • Stream the model out and use in machine learning.
  • Use machine learning in your red-node and node JS app
  • Show to contents on screen or save in cloudant DB

The above contents can be in sequence and also specify the flow of the article.

 

Getting the data for predictive model

Get the data in the form of excel sheet or csv, the data should have all the variables which can help generate the prediction score of the model.Please note all the variables we specify will have different prediction capability and the SPSS modeler will identify the right model and will generate the prediction scores.


Open the SPSS modeler and input an excel file and connect it with an input node, input node helps in identifying the target and variables for the model.

Lets take the drug example, it will detect the other body vitals by checking the sodium and potassium levels using the prediction model.


Important: To connect two nodes, you need to press F2 on source node and wait for an icon to appear and then drag it to target node, I got confused for a while on how to connect two nodes.

Lets import the excel sheet, as shown below.

image


Its in demo folder of the SPSS modeler installation.

image

So Drug1n is the input node and contains data which need to be fed to get the model.


image

image


This is just to get the ratio of  sodium to potassium and feed it to the input node, input node is very important node and it maps the input variables to the target fields.


Lets filter the data and send it to input node, the underline is filter node

image

Here if you see we are not sending the sodium and potassium and sending ration only, this is very helpful in SPSS modelling because many a times we need to filter data.


spss input node filter

Here is the actual magic that happens, we are defining the input data for model and the target which we need to achieve.

Lets try to use auto classifier and see if it can find an optimum model for us automatically.

Yes, SPSS has an auto classifier which can find the right model for you, if you don’t know which model might fit here, else you need to know all the models and apply yourself.



image

Lets connect the two nodes, input and the auto classifier and run it, it might consume a lot of memory as there are parallel executors which will run to find out the right model.

Hang in there for a while and let the classifier work.

image


Press the green button

image

So we have the results now.

image


This golden nugget is the model, lets double click and open and see what all models are generated.


We got the following output from the classifier.

image


I will go with C& R tree which makes decision trees based on the variables inside the data.


Now lets cancel this dialog and delete the golden nugget and the auto classifier node, now we will drag drop the C& R model node from the modelling tab and test it.


image

So this predictive model has the cognitive capabilities and can predict the drug that should be fit for a patient if the body vitals are entered.


Lets see some data in action, so currently the golden nugget is trained and will have decision trees for the input data.


image

Sodium to potassium ratio is the biggest prediction and second is the blood pressure.

Decision tree is shown below and is based on the prediction scores.

image

But, what to do now ? How to use it with IBM Watson prediction service (Now Machine learning service)

We will see in a short while.


Lets create a table node and this  will be our scoring terminal node which will help the prediction service to get the output from the IBM SPSS model.


Now lets make a scoring terminal node else you won’t be able to use it with Watson.

Go to tools –> streaming options –> Deployment and select the table and make it the scoring node.




image


image

Select table and the flow should turn solid blue and your model is ready for Watson.

image

Now again try to run the model and you should see prediction scores and status.

image


This explains the model confidence for the drugs which should be suggested to parties with these vitals.


Great, now we are ready to use it with watson, DRUG1n is our input scoring node and we will use this in our code either nodeJS or whatever SDK you are using to call the model.

I think we need to break the article, we will see how these working model will be fed into the watson and how we will call it from node-red or nodejs applications.


Keep Reading !








































































 

 

 

No comments:

Post a Comment