Jasonntone commited on
Commit
3abaf7b
·
verified ·
1 Parent(s): 11fd7a1

Upload 9 files

Browse files
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # type: ignore
2
+ import numpy as np
3
+ import pandas as pd
4
+ import seaborn as sns # type: ignore
5
+ import matplotlib.pyplot as plt
6
+ import base64
7
+ import pickle
8
+ import time
9
+
10
+ @st.cache_data
11
+ def load_data(dataset):
12
+ df = pd.read_csv(dataset)
13
+ return df
14
+ def filedownload(df):
15
+ csv = df.to_csv(index=False)
16
+ b64 = base64.b64encode(csv.encode()).decode() # strings <-> bytes conversions
17
+ href = f'<a href="data:file/csv;base64,{b64}" download="diabete_predictions.csv">Download CSV File</a>'
18
+ href2 = f'<a href="https://huggingface.co/spaces/Jasonntone/Brain_Stroke"></a>'
19
+ return href,href2
20
+ data = load_data('dataset/brain_stroke.csv')
21
+ meanGlucose = data['avg_glucose_level'].mean()
22
+ meanBmi = data['bmi'].mean()
23
+ meanAge = data['age'].mean()
24
+ st.sidebar.image('images/ahat.png',width=280)
25
+
26
+ def main():
27
+ st.markdown("<h1 style='text-align:center;color: red;'>Streamlit Brain Stroke Prediction App</h1>",unsafe_allow_html=True)
28
+ st.markdown("<h2 style='text-align:center;color: grey;'>Brain Stroke study in USA</h2>",unsafe_allow_html=True)
29
+ menu = ['Home','Analysis','Data Visualization','Machine Learning']
30
+ choice = st.sidebar.selectbox('Select Menu', menu)
31
+ if choice == 'Home':
32
+ left,middle,right = st.columns((2,3,2))
33
+ with middle:
34
+ col4, col5, col6 = st.columns(3)
35
+ with col4:
36
+ temp = st.metric(label="Average Glucose Level", value=meanGlucose, delta="From 5010 To 2012")
37
+ with col5:
38
+ temp = st.metric(label="Average BMI", value=meanBmi, delta="From 2010 To 2012")
39
+ with col6:
40
+ temp = st.metric(label="Average Age", value=meanAge, delta="From 2010 To 2012")
41
+ st.image('images/ahat.png',width=280)
42
+ if choice == 'Analysis':
43
+ st.subheader('Brain Stroke Dataset')
44
+ st.write(data.head())
45
+ if st.checkbox('Summary'):
46
+ st.write(data.describe())
47
+ elif st.checkbox('Correlation'):
48
+ fig = plt.figure(figsize=(15,5))
49
+ st.write(sns.heatmap(data.corr(),annot=True))
50
+ st.pyplot(fig)
51
+ elif choice == 'Data Visualization':
52
+ if st.checkbox('Countplot'):
53
+ fig = plt.figure(figsize=(15,5))
54
+ sns.countplot(x='age',data=data)
55
+ st.pyplot(fig)
56
+ elif st.checkbox('Scatterplot'):
57
+ fig = plt.figure(figsize=(15,5))
58
+ sns.scatterplot(x='avg_glucose_level',y='age',data=data,hue='stroke')
59
+ st.pyplot(fig)
60
+ elif choice == 'Machine Learning':
61
+ tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart:✅ Visualisation", "📈🎯 Prediction"])
62
+ uploaded_file = st.sidebar.file_uploader('Upload your Dataset(.csv file)',
63
+ type=['csv'])
64
+ if uploaded_file:
65
+ df = load_data(uploaded_file)
66
+ with tab1:
67
+ st.subheader('Loaded Dataset')
68
+ st.write(df)
69
+ with tab2:
70
+ st.subheader("Heart Disease's Histogram")
71
+ fig = plt.figure(figsize=(8,8))
72
+ sns.histplot(x='heart_disease',data=data)
73
+ st.pyplot(fig)
74
+ with tab3:
75
+ model = pickle.load(open('./models/gbc_dump.pkl', 'rb')) # Load the trained model from disk
76
+ prediction = model.predict(df)
77
+ pp = pd.DataFrame(prediction, columns=['Prediction'])
78
+ ndf = pd.concat([df, pp], axis=1)
79
+ ndf['Prediction'].replace(0, 'No Stroke Risk', inplace=True)
80
+ ndf['Prediction'].replace(1, 'Stroke Risk', inplace=True)
81
+ st.header("📈🎯 Stroke Risk Prediction")
82
+ st.subheader("Predictions")
83
+ st.write(ndf)
84
+
85
+ if st.button(' 💾 Download csv file'):
86
+ st.markdown(filedownload(ndf), unsafe_allow_html=True)
87
+
88
+
89
+
90
+
91
+ if __name__ == '__main__':
92
+ main()
brain_stroke.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
dataset/brain_stroke.csv ADDED
The diff for this file is too large to render. See raw diff
 
dataset/tuto.pbix ADDED
Binary file (47.1 kB). View file
 
images/TIA.png ADDED
images/ahat.png ADDED
models/ada_dump.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65e1911a9f5efcdc68af77ffc1d7fd18b05501d40d6167eae0610a31631fe18e
3
+ size 28671
models/gbc_dump.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18713af9f1cd67969b431b0626850fd8982a629795d746ad4a3a9eb806b05beb
3
+ size 136292
models/rf_dump.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b94fc17908bdf1f7d63b6e9dc91a4175bca025b1fba1da23cdd90505ae147999
3
+ size 5636386