IBM Auto AI Predict Early Stage Diabetes - Part 2
Published: 2021-05-02 15:15:59

# Get the data for our machine learning model

So in order for us to create a machine learning model first we need some data, the data that we need to have is data that has an output out of it for example :

| age | blood sugar level | class |
| --------- |:---------:| -------:|
| 10 | 10 mg | yes |
| 27 | 12 mg | no |
| 50 | 9 mg | yes |

As you can see above is some example data that we want, it has the data to determine whether or not this people has diabetes or no, as you can see there is `age` data, `blood sugar level` data, and `class` data from the example above, we can see that class data is used for determining whether or not this people has some diabetes or no and the other data is for the input data, so the data that we need is a data that have input and output like that, for the example above, `age` and `blood sugar` is the input, and `class` is the output to determine whether or no we had some early stage diabetes.

So to get this data we can go to some website like [https://www.kaggle.com/](https://www.kaggle.com/) here you can see so many free data that you can use, we will use this data by `ishandutta` that collect the data from some patients in bangladesh[[1][1]], this is exactly the data that we need, because it has some input data and also the output data

<figure>
  <img src="https://i.gyazo.com/6be18c743e7fedffae9394bdce7691c5.png">
  <figcaption>some example data of diabetes early stage risk</figcaption>
</figure>

# Import the data to IBM Auto AI
So in order for us to get some prediction to our data we need some tools to make it easy for us to do that, luckily IBM create some tools called IBM Auto AI, using this you can create machine learning easily and you can get the data as a web service as well so easily, now go to this [link](https://jp-tok.dataplatform.cloud.ibm.com) and login with your IBM ID and password, after you login click on view all project like below :

![view all project](https://i.gyazo.com/e2c867972caa6a3dc2d419065a10b8b8.gif)

Click on new project and click on create an empty project :

![new project](https://i.gyazo.com/1b1483a54019eb01d433fa0448d548cb.gif)

Fill in the project name and if you want you can fill in the project description, it's optional, you can leave it blank, after that click `create` :

![project name](https://i.gyazo.com/fdee2467b2c04e54a0722cb28f152358.gif)

Select the Settings tab.

![project name](https://i.gyazo.com/36e09a90a1c9fb4917f1c17b89f9def1.gif)

Scroll down to the Associated services section. If there is no machine learning service, click `Add services`, select `Watson`

![click service](https://i.gyazo.com/77b44c5a4531c4e424638378821935b6.gif)

Then select `Machine learning` and click add.

![machine learning](https://i.gyazo.com/c7a115ec04947091a86424803c514343.gif)

 Scroll down and select the lite plan then click Create.

![create](https://i.gyazo.com/52ae8347584a5f8e9a6b46b3179a360b.gif)

You're successfully create a watson machine learning service, if there is a success message like this :

![success](https://i.gyazo.com/617c121ef83314cda0ab0c5895381fec.png)

After we add watson machine learning service now we need to add the data that we want to predict, download the data from [here](https://www.kaggle.com/ishandutta/early-stage-diabetes-risk-prediction-dataset), then after downloading, you will get `archive.zip` which inside of it you will get `diabetes_data_upload.csv`, Now let's go back to IBM watson studio and click on `assets`, and upload the data

![click assets](https://i.gyazo.com/94644470b358d965f892612abbe18d79.gif)

You will then get the data uploaded like this :

![uploaded](https://i.gyazo.com/19dc85777c8529b4f3c3247035901b71.png)

After that check the data that you uploaded before, then click `add to project` then also click `AutoAI Experiment`

![auto ai experiment](https://i.gyazo.com/2f046c92d39ca3da7b85ac9b71d7ee9d.gif)

If you haven't associate your project with the watson machine learning service click `Associate a Machine Learning service instance` and click `reload` after you associate it

![machine](https://i.gyazo.com/cb469283aea7ac00f9e512d0e179a2f9.png)

After you associate it, it will look like this :

![associate](https://i.gyazo.com/48e8ae94138c0b576d45271a4359c857.png)

And after that, click `create`, then you need to add data source, click `Select from project` and click our dataset that we create earlier then click `select asset`

![dataset](https://i.gyazo.com/f69598d7395872f78cccb30bff9a491d.png)

After that we need to add prediction column, we gonna click column named `class` because this column determine whether or not our patient get diabetes based on some data on the left column

![pick prediction column](https://i.gyazo.com/86e0bba72922524140761345bde7167d.png)

If you click on `experiment settings`

![experiment setting](https://i.gyazo.com/2356d0257090d0d24545420b66ffd0ca.png)

You can also remove some feature that you think you don't need but for now let's use any of the column

After that click run experiment, and wait for it to be done

![wait](https://i.gyazo.com/bad757d2f1114139114c98b71a45a8cb.png)

After it's done you can see that `ExtraTreesClassifier` is picked, with accuracy of 0.933 the best out of other pipeline with some enhancements

![extra](https://i.gyazo.com/991944874d67c6a47eaf23677c56fb90.png)

After that you can also save the code to jupyter notebook by clicking `Save code`

![save](https://i.gyazo.com/35865da92b4a9ad88ca1631d2dc74964.gif)

And if you want to see your jupyter notebook, go to assets and click the file in the notebook section

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l7hf4nx4bbbt0tfoto0h.png)

Then after that we need to create model, in order to do that we need to click `Save as` click `Model` then click `Create`, this model will be used to predict if we got early risk diabetes or no

![model](https://i.gyazo.com/00a69e25c8e145af2098afa3f9857730.gif)

Then after we create our model we need to deploy it as a web service so any platform can call it from the web. Now go to your newly created model and click on `Promote to Deployment space`

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wbmlc24ug6lg81jble3.png)

After that click on `new space` because we don't have any space yet

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7bhfvy40ryd99pe6csa0.png)

Fill in the name and click create

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cipcjcw2x1fuqdwj1c4.png)

Our newly target space will be automatically selected, then after that click `Promote`

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7d6rp4mhv5dcl0wepsw.png)

You will get redirected to your project homepage click on the `deployment space` hyperlink

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwrt6axogupiqf4ov13u.png)

When you click on deploy it will say there is no machine learning service associated with this space

![space](https://i.gyazo.com/af7f11242963efd851f3b17d1e8caf8a.gif)

Click on `Go to space settings`

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2sczlnpt3m6p6yd41cxf.png)

Click on associate instance

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yn1amf22yfayvt3htljc.png)

Then select your machine learning instance, in this case my machine learning instance name is `Machine Learning-wr`

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w89li72hjv8yv0pomgs1.png)

After that click on assets again, then click deploy again

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhc63aftpkf5ckcuw7ch.png)

Click deployment type `online` and named it `diabetes deploy` or whatever name you want then click `create`

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dw6d4zendapm00sz7wc6.png)

Refresh the page and click deployments and you can see that your deployment is still in progress, we will wait until it's complete

![wait](https://i.gyazo.com/9e2e198724b7ebd0e228f2356e931a4a.gif)

After it getting deployed it will showed like this

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axhetfmloock8vwcpdry.png)

We can now try to test our machine learning model is it gonna output the same as in the csv or no,in order to do that click on `diabetes deploy` hyperlink then click on test

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qaj8z18rfcyytudfxmm.png)

We can see that our input is exactly like what we have in csv and the output is our `class` column to determine whether or not we are in an early stage of diabetes let's input first data one by one we gonna input this data below, and the input should be `Positive` which mean we are in the early stage of diabetes

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k5kezufdmjspgjmwdwu.png)
  
After we added our input data click `add to list`

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnv9ia5iuzi33szjh4t2.png)

After that click on `Predict` and we can see the result is `Positive` which mean our machine learning model accuracy is great

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzgm8bnhcbsdx01wtmhp.png)

Now we can move forward and connect our machine learning model to web application in part 3 

 
 
  
 
 
   

    
 









[1]: https://www.kaggle.com/ishandutta/early-stage-diabetes-risk-prediction-dataset
[2]: https://www.ibm.com/cloud/garage/dte/tutorial/ibm-watson-studio-autoai-modeling-rest-us?cm_sp=freelancer-_-AutoAI-_-cta