Spaces:
Runtime error
Runtime error
saritha Miryala
commited on
Add files via upload
Browse files- README.md +7 -1
- app.py +178 -0
- requirements.txt +8 -0
README.md
CHANGED
|
@@ -1 +1,7 @@
|
|
| 1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# diabetes_prediction
|
| 2 |
+
Preview of the Project
|
| 3 |
+
|
| 4 |
+

|
| 5 |
+

|
| 6 |
+

|
| 7 |
+

|
app.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pip install streamlit
|
| 2 |
+
#pip install pandas
|
| 3 |
+
#pip install sklearn
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# IMPORT STATEMENTS
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import pandas as pd
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import numpy as np
|
| 11 |
+
import matplotlib.pyplot as plt
|
| 12 |
+
import plotly.figure_factory as ff
|
| 13 |
+
from sklearn.metrics import accuracy_score
|
| 14 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 15 |
+
from sklearn.model_selection import train_test_split
|
| 16 |
+
import seaborn as sns
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
df = pd.read_csv('diabetes.csv')
|
| 21 |
+
|
| 22 |
+
# HEADINGS
|
| 23 |
+
st.title('Diabetes Checkup')
|
| 24 |
+
st.sidebar.header('Patient Data')
|
| 25 |
+
st.subheader('Training Data Stats')
|
| 26 |
+
st.write(df.describe())
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# X AND Y DATA
|
| 30 |
+
x = df.drop(['Outcome'], axis = 1)
|
| 31 |
+
y = df.iloc[:, -1]
|
| 32 |
+
x_train, x_test, y_train, y_test = train_test_split(x,y, test_size = 0.2, random_state = 0)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# FUNCTION
|
| 36 |
+
def user_report():
|
| 37 |
+
pregnancies = st.sidebar.slider('Pregnancies', 0,17, 3 )
|
| 38 |
+
glucose = st.sidebar.slider('Glucose', 0,200, 120 )
|
| 39 |
+
bp = st.sidebar.slider('Blood Pressure', 0,122, 70 )
|
| 40 |
+
skinthickness = st.sidebar.slider('Skin Thickness', 0,100, 20 )
|
| 41 |
+
insulin = st.sidebar.slider('Insulin', 0,846, 79 )
|
| 42 |
+
bmi = st.sidebar.slider('BMI', 0,67, 20 )
|
| 43 |
+
dpf = st.sidebar.slider('Diabetes Pedigree Function', 0.0,2.4, 0.47 )
|
| 44 |
+
age = st.sidebar.slider('Age', 21,88, 33 )
|
| 45 |
+
|
| 46 |
+
user_report_data = {
|
| 47 |
+
'pregnancies':pregnancies,
|
| 48 |
+
'glucose':glucose,
|
| 49 |
+
'bp':bp,
|
| 50 |
+
'skinthickness':skinthickness,
|
| 51 |
+
'insulin':insulin,
|
| 52 |
+
'bmi':bmi,
|
| 53 |
+
'dpf':dpf,
|
| 54 |
+
'age':age
|
| 55 |
+
}
|
| 56 |
+
report_data = pd.DataFrame(user_report_data, index=[0])
|
| 57 |
+
return report_data
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# PATIENT DATA
|
| 63 |
+
user_data = user_report()
|
| 64 |
+
st.subheader('Patient Data')
|
| 65 |
+
st.write(user_data)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# MODEL
|
| 71 |
+
rf = RandomForestClassifier()
|
| 72 |
+
rf.fit(x_train, y_train)
|
| 73 |
+
user_result = rf.predict(user_data)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# VISUALISATIONS
|
| 78 |
+
st.title('Visualised Patient Report')
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# COLOR FUNCTION
|
| 83 |
+
if user_result[0]==0:
|
| 84 |
+
color = 'blue'
|
| 85 |
+
else:
|
| 86 |
+
color = 'red'
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Age vs Pregnancies
|
| 90 |
+
st.header('Pregnancy count Graph (Others vs Yours)')
|
| 91 |
+
fig_preg = plt.figure()
|
| 92 |
+
ax1 = sns.scatterplot(x = 'Age', y = 'Pregnancies', data = df, hue = 'Outcome', palette = 'Greens')
|
| 93 |
+
ax2 = sns.scatterplot(x = user_data['age'], y = user_data['pregnancies'], s = 150, color = color)
|
| 94 |
+
plt.xticks(np.arange(10,100,5))
|
| 95 |
+
plt.yticks(np.arange(0,20,2))
|
| 96 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 97 |
+
st.pyplot(fig_preg)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# Age vs Glucose
|
| 102 |
+
st.header('Glucose Value Graph (Others vs Yours)')
|
| 103 |
+
fig_glucose = plt.figure()
|
| 104 |
+
ax3 = sns.scatterplot(x = 'Age', y = 'Glucose', data = df, hue = 'Outcome' , palette='magma')
|
| 105 |
+
ax4 = sns.scatterplot(x = user_data['age'], y = user_data['glucose'], s = 150, color = color)
|
| 106 |
+
plt.xticks(np.arange(10,100,5))
|
| 107 |
+
plt.yticks(np.arange(0,220,10))
|
| 108 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 109 |
+
st.pyplot(fig_glucose)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
# Age vs Bp
|
| 114 |
+
st.header('Blood Pressure Value Graph (Others vs Yours)')
|
| 115 |
+
fig_bp = plt.figure()
|
| 116 |
+
ax5 = sns.scatterplot(x = 'Age', y = 'BloodPressure', data = df, hue = 'Outcome', palette='Reds')
|
| 117 |
+
ax6 = sns.scatterplot(x = user_data['age'], y = user_data['bp'], s = 150, color = color)
|
| 118 |
+
plt.xticks(np.arange(10,100,5))
|
| 119 |
+
plt.yticks(np.arange(0,130,10))
|
| 120 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 121 |
+
st.pyplot(fig_bp)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
# Age vs St
|
| 125 |
+
st.header('Skin Thickness Value Graph (Others vs Yours)')
|
| 126 |
+
fig_st = plt.figure()
|
| 127 |
+
ax7 = sns.scatterplot(x = 'Age', y = 'SkinThickness', data = df, hue = 'Outcome', palette='Blues')
|
| 128 |
+
ax8 = sns.scatterplot(x = user_data['age'], y = user_data['skinthickness'], s = 150, color = color)
|
| 129 |
+
plt.xticks(np.arange(10,100,5))
|
| 130 |
+
plt.yticks(np.arange(0,110,10))
|
| 131 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 132 |
+
st.pyplot(fig_st)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# Age vs Insulin
|
| 136 |
+
st.header('Insulin Value Graph (Others vs Yours)')
|
| 137 |
+
fig_i = plt.figure()
|
| 138 |
+
ax9 = sns.scatterplot(x = 'Age', y = 'Insulin', data = df, hue = 'Outcome', palette='rocket')
|
| 139 |
+
ax10 = sns.scatterplot(x = user_data['age'], y = user_data['insulin'], s = 150, color = color)
|
| 140 |
+
plt.xticks(np.arange(10,100,5))
|
| 141 |
+
plt.yticks(np.arange(0,900,50))
|
| 142 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 143 |
+
st.pyplot(fig_i)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
# Age vs BMI
|
| 147 |
+
st.header('BMI Value Graph (Others vs Yours)')
|
| 148 |
+
fig_bmi = plt.figure()
|
| 149 |
+
ax11 = sns.scatterplot(x = 'Age', y = 'BMI', data = df, hue = 'Outcome', palette='rainbow')
|
| 150 |
+
ax12 = sns.scatterplot(x = user_data['age'], y = user_data['bmi'], s = 150, color = color)
|
| 151 |
+
plt.xticks(np.arange(10,100,5))
|
| 152 |
+
plt.yticks(np.arange(0,70,5))
|
| 153 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 154 |
+
st.pyplot(fig_bmi)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
# Age vs Dpf
|
| 158 |
+
st.header('DPF Value Graph (Others vs Yours)')
|
| 159 |
+
fig_dpf = plt.figure()
|
| 160 |
+
ax13 = sns.scatterplot(x = 'Age', y = 'DiabetesPedigreeFunction', data = df, hue = 'Outcome', palette='YlOrBr')
|
| 161 |
+
ax14 = sns.scatterplot(x = user_data['age'], y = user_data['dpf'], s = 150, color = color)
|
| 162 |
+
plt.xticks(np.arange(10,100,5))
|
| 163 |
+
plt.yticks(np.arange(0,3,0.2))
|
| 164 |
+
plt.title('0 - Healthy & 1 - Unhealthy')
|
| 165 |
+
st.pyplot(fig_dpf)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# OUTPUT
|
| 170 |
+
st.subheader('Your Report: ')
|
| 171 |
+
output=''
|
| 172 |
+
if user_result[0]==0:
|
| 173 |
+
output = 'You are not Diabetic'
|
| 174 |
+
else:
|
| 175 |
+
output = 'You are Diabetic'
|
| 176 |
+
st.title(output)
|
| 177 |
+
st.subheader('Accuracy: ')
|
| 178 |
+
st.write(str(accuracy_score(y_test, rf.predict(x_test))*100)+'%')
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==1.1.4
|
| 2 |
+
matplotlib==3.3.3
|
| 3 |
+
seaborn==0.11.1
|
| 4 |
+
numpy==1.18.5
|
| 5 |
+
streamlit==0.72.0
|
| 6 |
+
plotly==4.14.1
|
| 7 |
+
Pillow==8.0.1
|
| 8 |
+
scikit_learn==0.24.0
|