Spaces:
Sleeping
Sleeping
File size: 4,029 Bytes
e3cc4c2 |
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 |
import streamlit as st # type: ignore
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import base64
import pickle
import time
from pycaret.classification import load_model
@st.cache_data
def load_data(dataset):
df = pd.read_csv(dataset)
return df
st.sidebar.image('images/diabetes.jpg',width=280)
def main():
st.markdown("<h1 style='text-align:center;color: skyblue;'>Streamlit Diabetes Prediction App</h1>",unsafe_allow_html=True)
st.markdown("<h2 style='text-align:center;color: grey;'>Diabetes study in Cameroon</h2>",unsafe_allow_html=True)
menu = ['Home','Analysis','Data Visualization','Machine Learning']
choice = st.sidebar.selectbox('Select Menu', menu)
data = load_data('dataset/diabetes.csv')
if choice == 'Home':
left,middle,right = st.columns((2,3,2))
with middle:
st.image("images/2.jpg",width=300)
st.write("This is an app that will analyse diabetes Datas with some python tools that can optimize decisions")
st.subheader('Diabetes Informations')
st.write('In Cameroon, the prevalence of diabetes in adults in urban areas is currently estimated at 6 β 8%, with as much as 80% of people living with diabetes who are currently undiagnosed in the population. Further, according to data from Cameroon in 2002, only about a quarter of people with known diabetes actually had adequate control of their blood glucose levels. The burden of diabetes in Cameroon is not only high but is also rising rapidly. Data in Cameroonian adults based on three cross-sectional surveys over a 10-year period (1994β2004) showed an almost 10-fold increase in diabetes prevalence.')
if choice == 'Analysis':
st.subheader('Diabetes Dataset')
st.write(data.head())
if st.checkbox('Summary'):
st.write(data.describe())
elif st.checkbox('Correlation'):
fig = plt.figure(figsize=(15,5))
st.write(sns.heatmap(data.corr(),annot=True))
st.pyplot(fig)
elif choice == 'Data Visualization':
if st.checkbox('Countplot'):
fig = plt.figure(figsize=(15,5))
sns.countplot(x='Age',data=data)
st.pyplot(fig)
elif st.checkbox('Scatterplot'):
fig = plt.figure(figsize=(15,5))
sns.scatterplot(x='Glucose',y='Age',data=data,hue='Outcome')
st.pyplot(fig)
elif choice == 'Machine Learning':
tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart:β
Visualisation", "ππ― Prediction"])
uploaded_file = st.sidebar.file_uploader('Upload your Dataset(.csv file)',
type=['csv'])
if uploaded_file:
df = load_data(uploaded_file)
with tab1:
st.subheader('Loaded Dataset')
st.write(df)
with tab2:
st.subheader("Glucose's Histogram")
fig = plt.figure(figsize=(8,8))
sns.histplot(x='Glucose',data=data)
st.pyplot(fig)
with tab3:
model = load_model('lr')
prediction = model.predict(df)
pp = pd.DataFrame(prediction, columns=['Prediction'])
ndf = pd.concat([df, pp], axis=1)
ndf['Prediction'].replace(0, 'No Diabetes Risk', inplace=True)
ndf['Prediction'].replace(1, 'Diabetes Risk', inplace=True)
st.header("ππ― Diabete Risk Prediction")
st.subheader("Predictions")
st.write(ndf)
csv = ndf.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode()
href = f'<a href="data:file/csv;base64,{b64}" download="Diabete_Prediction.csv">Download CSV file</a>'
if st.button(' πΎ Download csv file'):
st.markdown(href, unsafe_allow_html=True)
if __name__ == '__main__':
main() |