top of page
Search

Diabetic Prediction- Using Deep Learning Neural Networks

  • amalpappalilramesh
  • May 14, 2022
  • 3 min read



Introduction

The main objective of this blog is a build and optimize a neural network and predict the possibility to check if a patient is diabetic or not based on medical records and parameter’s using deep learning. Here i will detail in fewer steps the method to create a model from a sample dataset for predicting diabetics in a patient.

Modules Used:

Here we will be using the following python libraries . I am using a google collab file to perform the scripting

Load the Dataset:

The data set folder has been uploaded to google drive and connected via mounting the drive in the collab as shown.





Dataset Overview

The data set contains the 10 columns. A quick overview on the 10 columns can be seen below .



Columns:10

Rows:668


Description:

Here is data set description using the describe method in pandas



Now let us look at the current distribution of data in the data set


Extracting features and Preprocessing


Now let us do some preprocessing of the data . Here we will try to keep a minimum cleaninng and wrangling as shown below:


1. Drop the id and Class columns as it is unwanted for model building


2. Label Encoding – Ensuring that we have numerical columns only








4. MODEL BUILDING:


For building the model , we need to choose the features/columns that we feel are relevent to the prediction . Here I am going to select the all 8 features to X1 and use it in splitting data set with 70-30 ratio.



Model Type used: Sequential and layers of network can be defined using Dense layers.

Optimization: Several numbers of Dense layers were tried out using keras models and the best. Accuracy was obtained using the below combination of dense layers

Activation Functions: used Rectified Linear Unit (relu for hidden layers) and sigmoid (for output layer)

Batch size : 64,32


The following Keras sequential model seems to perform better on accuracy .Hence we will go ahead with this one.












Let us also perform some steps to ensure there is not much of overfitting .Here i am using Early Stopping mechanism to stop the overfitting of features in the model.

Early Stopping – to stop overfitting


Compile the Keras Model - next steps is to compile the model . Here I have used Adam Optimizer as its efficient and it tunes itself. The following block of code performs the compilation of the model with loss function . Also to note is that i am using a learning rate of 0.01 as it yielded a better accuracy.


Fit the Model:- with train data and validation data

Once the model is compiled , next step is to fit the model using the fit method() . Here i have used a batch_size of 60 and 60 epochs to fit the model.


Validate the Model



Minimal amount of overfitting has been detected.

Drop out method tried-to reduce overfitting : No change in accuracy-hence going ahead with the current model.



9. Make Predictions using model.predict() -


Once the model is ready , we can apply it on the test set to make predictions. The following code uses a predict method to predict the values of whether a patient has diabetics or not .















Accuracy :



Test Predictions on the Test Dataset:

Now that we have identified the best model- we can perform the application on real time data . So for this the following steps are involved:




SUMMARY


Final Prediction’s:

For the final predictions – we use the optimized model and use to predict the test set as below:





Export as CSV – Updated the Class column with predictions for entire test set.

Final Export file is test-predictions.csv




Predictions Plot Observation – shows majority of the patients are non diabetic in the dataset.

.




Thats All folks

 
 
 

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2021 by techblog.ai.bcu.amal. Proudly created with Wix.com

bottom of page