File size: 6,071 Bytes
031882e
 
cb33c92
 
 
 
 
 
 
 
 
7e40384
 
ea9011c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e40384
ea9011c
7e40384
ea9011c
 
 
7e40384
ea9011c
 
 
7e40384
ea9011c
 
 
b7ca7ab
 
 
 
 
 
 
 
 
49eba0a
 
b7ca7ab
ea9011c
b7ca7ab
ea9011c
b7ca7ab
ea9011c
b7ca7ab
 
 
ea9011c
 
 
 
 
 
 
 
 
 
 
 
c464e43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#Model start

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt
import gradio as gr
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.model_selection import cross_val_score
from sklearn.metrics import r2_score
  
def main(Pregnancies,Glucose_level,BP,skin_thickness,Insulin,BMI,Diabetes_Function,Age):

  url="https://raw.githubusercontent.com/ADITHYASNAIR2021/Dataset-cart/main/diabetes.csv"
  diabetes_df = pd.read_csv(url)
  diabetes_df = diabetes_df.values
  X= diabetes_df[:,0:8] #Predictors
  y = diabetes_df[:,8] #Target 
  X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=.25)

  Log_reg = LogisticRegression(fit_intercept=True,C=1e15,solver='newton-cg',max_iter=300,penalty='l2',multi_class='ovr')
  Log_reg.fit(X_train,y_train)
  Log_pred = Log_reg.predict(X_test)

  #Accuracy
  lor_accuracy = accuracy_score(y_test,Log_pred)

  #Cross Validation
  logreg = LogisticRegression(max_iter=1500)
  scores_Log = cross_val_score(logreg , X_train , y_train , cv=20)
  scores_Log = scores_Log.mean()

  data = {'Pregancies':Pregnancies,'Glucose':Glucose_level,'BloodPressure':BP,'SkinThickness':skin_thickness,'Insulin':Insulin,'BMI':BMI,'DiabetesPedigreeFunction':Diabetes_Function,'Age':Age}
  index = [0]
  cust_df = pd.DataFrame(data, index)
  
  # Main output prediction 
  costpredLog = Log_reg.predict(cust_df)

  #Get the patients BMI information 

  if BMI == 0: 
        Bmi_eval="NA"

  elif BMI < 18.5: 
         Bmi_eval="You are Underweight" 

  elif BMI < 24.9: 
        Bmi_eval =" You have Normal weight"

  elif BMI >= 25 and BMI < 29.9: 
        Bmi_eval = " You are Pre Obese"

  elif BMI >= 30 and BMI < 34.9: 
        Bmi_eval = " You have class 1 Obesity "

  elif BMI >= 35 and BMI < 39.9: 
        Bmi_eval = " You have class 2 Obesity "

  elif BMI >= 40: 
        Bmi_eval ="You have class 3 obesity "

  else: 
       Bmi_eval = BMI

   # Get the patient's Diabetic information 

  if Glucose_level == 0: 
        Glucose_Eval ="NA"
    
  elif Glucose_level <= 140: 
        Glucose_Eval="You have a Normal Glucose Level"
    
  elif Glucose_level > 140 and Glucose_level < 198: 
        Glucose_Eval="you have Impaired Glucose Tolerance"
        
  elif Glucose_level > 198: 
        Glucose_Eval="You have a high Glucose Level "
        
  else: 
        Glucose_Eval = Glucose_level

 # Final prediction 

  if costpredLog ==0:
    Prediction = "There is less chance for the patient to catch diabetes"

  else:
    Prediction = "There is more chance for the patient to catch diabetes."

  return  Prediction,Bmi_eval,Glucose_Eval

iface = gr.Interface(fn = main,
                     
inputs =['number','number','number','number','number','number','number','number'],

outputs =['text','text','text'],

title="Onset of Diabetes prediction",

examples=[[2,120,120,25,20,25,1,25],[5,200,200,50,160,30,2,30]],

description ='''    Description
 
Some health issues are more serious than others. An example of a severe health issue is diabetes, which is an all-too-common condition
It is essential for people with diabetes to be diagnosed and treated as soon as possible, as high blood sugar levels can damage body organs and tissue,
resulting in complications such as nerve damage, kidney damage, heart attacks, strokes, peripheral vascular disease etc. While some risk factors of 
developing diabetes cannot be changed, healthy lifestyle choices can dramatically reduce a person’s chances of developing it. 

As we face these high numbers of diabetes and prediabetes cases, it’s important that everyone learns as much as they can about recognizing and preventing diabetes. 
All these points emphasise that diabetes can be really bad if not diagnosed properly so, 
with this AI tool, we can predict the onset of diabetes among people which will help them to adjust their lifestyles and other things correctly to prevent diabetes in the future.
                     

    Output0 - Describes the Prediction made
    Output1 - Analyse BMI
    Output2 - Analysis of Glucose level


More details about the Inputs taken and how they needed to be taken are given below:
    * Pregnancies (number of times pregnant)
    * glucose - two-hour plasma glucose concentration after 75g anhydrous glucose in mg/dl (Can check using a Glucometer at home, or at a clinic)
    * Blood Pressure (Diastolic Blood Pressure in mmHg)
    * Skin Thickness (Triceps skin fold thickness in mm)
    * Insulin Resistance (2 h serum insulin in mu U/ml)( Results could be obtained from a Clinic )
    * BMI (Body Mass Index in kg/m2), BMI can be calculated using the equation  = Weight/(Height²)
    * Age (years)
    * Pedigree Diabetes Function ('function that represents how likely they are to get the disease by extrapolating from their ancestor’s history )
      Generally, it's between 0 - 2.5, if there wasn't any ancestorial history of diabetes you can choose between 0 and 1, 
      and if there is any so can select between 1 - 2.5 regarding the seriousness of the family.
''',

article=''' Website created with Gradio for Hackathon'22

Dataset used is:- PIMA INDIANS DIABETES DATASET 

Description of the dataset used:- The Pima Indian Diabetes Dataset, originally from the National Institute of Diabetes and Digestive and Kidney Diseases 
contains information on 768 women from a population near Phoenix, Arizona, USA. The outcome tested was Diabetes, 258 tested positive and 500 tested negative. 
Therefore, there is one target (dependent) variable and the following attributes (TYNECKI, 2018):

To know more about the Tricep skin fold thickness measure 
visit this link:- https://ibb.co/4NDNNx1

Dataset Link - https://www.kaggle.com/datasets/uciml/pima-indians-diabetes-database

Reference 1 = https://rpubs.com/ikodesh/53189

Reference 2 = https://www.diabetes.co.uk/oral-glucose-tolerance-test.html 

''')

iface.launch(debug =True)