Prediction of Chronic Kidney Disease within 3 years of T2D


  1. Introdution
  2. Preparing CSV
  3. Using End point
    • 3.1 Creating model
    • 3.2 Creating Endpoint Config
    • 3.3 Creating Endpoint
    • 3.4 Invoking Endpoint
    • 3.5. Deleting the Endpoint - Optional
  4. Model Output

1. Introdution

Type2Diabetes(T2D) is a chronic condition and leads to several comorbidities. Chronic Kidney Disease among Type2Diabetes patients is one of the fastest growing epidemics.Prediction model helps to identify whether the person suffer by CKD within three years of T2D by taking into account various observational parameters and demographic details.

2. Preparing CSV

The csv file used in the model has 13 columns viz

  • AGE = Person's Age
  • Gender = Person's Gender
  • Race = Person belongs to which race
  • 20565-8 = Carbon dioxide, total [Moles/volume] in Blood
  • 2069-3 = Chloride [Moles/volume] in Blood
  • 2339-0 = Glucose [Mass/volume] in Blood
  • 2339-0 = Glucose [Mass/volume] in Blood
  • 2571-8 = Triglyceride [Mass/volume] in Serum or Plasma
  • 29463-7 = Body weight
  • 33914-3 = Glomerular filtration rate/1.73 sq M.predicted [Volume Rate/Area] in Serum or Plasma by Creatinine-based formula
  • 38483-4 = Creatinine [Mass/volume] in Blood
  • 4544-3 = Hematocrit [Volume Fraction] of Blood by Automated count
  • 777-3 = Platelets [#/volume] in Blood by Automated count

Same kind of CSV file should be fed to the model for best output.

For reference, A sample CSV file is attached in the link. The user only needs to clik on the link to get it downloaded to the local. The data should be in a similar format like the sample csv.

Download sample Data from the link : Data Source for Chronic Kidney Disease

In [ ]:
import pandas as pd
df = pd.read_csv('S3/Sagemaker path of CKD.csv file')

3. Using Endpoint

The model can be directly accessed via the console provided by AWS. However, for a more customized process one can access the model using the below code as well.

3.1 Creating Model

To create a model, import boto3, sagemaker and get the arn of the model package

In [ ]:
import boto3
import sagemaker
role = sagemaker.get_execution_role()
smmp = boto3.client('sagemakermp')
modelName='Name of the model'
modelArn = 'Model ARN name'
createHeatIndexResponse = smmp.create_model(ModelName=modelName,\
                             Containers=[{'ModelPackageName': modelArn}],\
                             EnableNetworkIsolation=True )

3.2 Creating Endpoint Config

In [ ]:
configName ='<Input Configuration Name>'
instanceType = '<Input Instance Type>'
createHeatIndexEndpointConfig = smmp.create_endpoint_config(EndpointConfigName = configName, ProductionVariants = [{'InstanceType':instanceType, 'InitialInstanceCount':1, 'ModelName':modelName, 'VariantName':'xyz'}])

3.3 Creating Endpoint

In [ ]:
endpointName = '<Input Endpoint Name>'
createHeatIndexEndpoint = smmp.create_endpoint(EndpointName = endpointName, EndpointConfigName = configName)

3.4 Invoking Endpoint

In [ ]:
runtime = boto3.Session().client('runtime.sagemaker')

#Reading Input Data 
with open('sample.csv','rb') as f:
    payload =

response = runtime.invoke_endpoint(EndpointName = endpointName, ContentType = 'text/csv', Body = payload)
result = response['Body'].read().decode()

#Writing Output Data 
with open('sampleOutput.txt','w') as f:

3.5. Deleting the Endpoint - Optional

If you're ready to be done with this notebook, please run the delete_endpoint line in the cell below. This will remove the hosted endpoint you created and avoid any charges from a stray instance being left on

In [ ]:

4. Model Output

In [ ]:
with open("./sampleOutput.txt","r") as f:
    sampleResponse = sampleResponse.split('\n')