nugrahatheo commited on
Commit
6eb2dc3
1 Parent(s): 9250603

initial commit

Browse files
Files changed (11) hide show
  1. about.py +21 -0
  2. app.py +29 -0
  3. cc.jpeg +0 -0
  4. eda.py +161 -0
  5. h8dsft_P1G3_theo.csv +300 -0
  6. list_num_cols.txt +1 -0
  7. model_gbc.pkl +0 -0
  8. model_rfc.pkl +0 -0
  9. model_scaler.pkl +0 -0
  10. prediction.py +82 -0
  11. requirements.txt +9 -0
about.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+
4
+ def run():
5
+ # Add Picture
6
+ image = Image.open('cc.jpeg')
7
+ st.image(image, caption=None, width=700)
8
+ # Title
9
+ st.title('ABOUT THIS PROJECT')
10
+ st.markdown('---')
11
+ st.write('###### This project aims to create a model with Random Forest Classifier and GradientBoost Classifier algorithms to predict whether a patient will die or not due to heart failure.')
12
+ st.markdown('---')
13
+
14
+ st.write('Feel free to contact me on:')
15
+ st.write('[GITHUB](https://github.com/theonugraha)')
16
+ st.write('or')
17
+ st.write('[LINKEDIN](https://www.linkedin.com/in/nugrahatheo/)')
18
+
19
+
20
+ if __name__ == '__main__':
21
+ run()
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
+ import eda
4
+ import prediction
5
+ import about
6
+
7
+ st.write('### PREDICTION OF DEATH DUE TO HEART FAILURE')
8
+ st.write('##### This page created by [Theo Nugraha](https://github.com/theonugraha)')
9
+ st.markdown('---')
10
+
11
+ selected = option_menu(None, ["About", "EDA", "Predict"],
12
+ icons=['house', 'bar-chart', 'gear'],
13
+ menu_icon="cast", default_index=0, orientation="horizontal",
14
+ styles={
15
+ "icon": {"color": "red", "font-size": "15px"},
16
+ "nav-link": {"font-size": "15px", "text-align": "left", "margin":"1px", "--hover-color": "#eee"},
17
+ "nav-link-selected": {"background-color": "lightgrey"},
18
+ }
19
+ )
20
+
21
+ selected
22
+
23
+
24
+ if selected == 'EDA':
25
+ eda.run()
26
+ elif selected == 'Predict':
27
+ prediction.run()
28
+ else:
29
+ about.run()
cc.jpeg ADDED
eda.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+ from PIL import Image
7
+
8
+ st.set_page_config(
9
+ page_title = 'Prediction of Death Due To Heart Failure',
10
+ layout ='centered',
11
+ initial_sidebar_state='expanded'
12
+ )
13
+
14
+ def run():
15
+ # Sub Header
16
+ st.subheader('EDA for Analizing Dataset Death Due To Heart Failure', )
17
+
18
+ # Separated Line
19
+ st.markdown('---')
20
+
21
+ # Show Data Frame
22
+ st.write('#### Dataset Death Due To Heart Failure')
23
+ data = pd.read_csv('h8dsft_P1G3_theo.csv')
24
+ st.dataframe(data)
25
+
26
+ # Histogram based user input
27
+ st.write('#### Histogram')
28
+ option = st.selectbox('Choose Column : ', ('age','creatinine_phosphokinase', 'ejection_fraction', 'platelets',
29
+ 'serum_creatinine', 'serum_sodium', 'time'))
30
+ fig = plt.figure(figsize=(20, 10))
31
+ sns.histplot(data[option], bins=30, kde=True)
32
+ st.pyplot(fig)
33
+
34
+ # Pie chart `DEATH_EVENT`
35
+ death_data = data["DEATH_EVENT"].value_counts()
36
+ st.write('#### Pie Chart DEATH EVENT')
37
+ fig = plt.figure(figsize=(6, 6))
38
+ plt.pie(death_data, labels=["Not Death", "Death"], autopct="%1.1f%%", startangle=90, colors=["lightblue", "lightcoral"])
39
+ st.pyplot(fig)
40
+ with st.expander("See explanation"):
41
+ st.write('''
42
+ Based on the diagram above, we can understand that the surviving patients outnumber the deceased patients. It also shows that the proportion of the two classes is not balanced.
43
+ ''')
44
+
45
+ # Pie chart `sex`
46
+ sex_data = data["sex"].value_counts()
47
+ st.write('#### Pie Chart SEX')
48
+ fig = plt.figure(figsize=(6, 6))
49
+ plt.pie(sex_data, labels=["Woman", "Man"], autopct="%1.1f%%", startangle=90, colors=["lightgreen","lightblue"])
50
+ st.pyplot(fig)
51
+ with st.expander("See explanation"):
52
+ st.write('''
53
+ Based on the diagram above, we can understand that the woman patients outnumber the man patients. It also shows that the proportion of the two classes is not balanced.
54
+ ''')
55
+
56
+ # Pie chart `diabetes`
57
+ diabetes_data = data["diabetes"].value_counts()
58
+ st.write('#### Pie Chart DIABETES')
59
+ fig = plt.figure(figsize=(6, 6))
60
+ plt.pie(diabetes_data, labels=["No Diabetes", "Diabetes"], autopct="%1.1f%%", startangle=90, colors=["lightgreen","red"])
61
+ st.pyplot(fig)
62
+ with st.expander("See explanation"):
63
+ st.write('''
64
+ Based on the diagram above, we can know that patients who do not have diabetes are more than patients who have diabetes.
65
+ ''')
66
+
67
+ # Pie chart `anaemia`
68
+ anaemia_data = data["anaemia"].value_counts()
69
+ st.write('#### Pie Chart ANAEMIA')
70
+ fig = plt.figure(figsize=(6, 6))
71
+ plt.pie(anaemia_data, labels=["No Anaemia", "Anaemia"], autopct="%1.1f%%", startangle=90, colors=["lightyellow","red"])
72
+ st.pyplot(fig)
73
+ with st.expander("See explanation"):
74
+ st.write('''
75
+ Based on the diagram above, we can know that patients who do not have anaemia are more than patients who have anaemia.
76
+ ''')
77
+
78
+ # Pie chart `high_blood_pressure`
79
+ hbp_data = data["high_blood_pressure"].value_counts()
80
+ st.write('#### Pie Chart HIGH BLOOD PRESSURE')
81
+ fig = plt.figure(figsize=(6, 6))
82
+ plt.pie(hbp_data, labels=["No High Blood Pressure", "High Blood Pressure"], autopct="%1.1f%%", startangle=90, colors=["lightblue","red"])
83
+ st.pyplot(fig)
84
+ with st.expander("See explanation"):
85
+ st.write('''
86
+ Based on the diagram above, we can know that patients who do not have high blood pressure are more than patients who have high blood pressure.
87
+ ''')
88
+
89
+ # Pie chart `smoking`
90
+ smoking_data = data["smoking"].value_counts()
91
+ st.write('#### Pie Chart SMOKING')
92
+ fig = plt.figure(figsize=(6, 6))
93
+ plt.pie(smoking_data, labels=["No Smoking", "Smoking"], autopct="%1.1f%%", startangle=90, colors=["lightgrey","red"])
94
+ st.pyplot(fig)
95
+ with st.expander("See explanation"):
96
+ st.write('''
97
+ Based on the diagram above, we can know that patients who do not smoke are more than patients who smoke.
98
+ ''')
99
+
100
+ # Bar Plot 1
101
+ st.write('#### Plot Death Event Based on Sex')
102
+ fig = plt.figure(figsize=(15, 5))
103
+ death = sns.countplot(data=data, x="sex", hue="DEATH_EVENT")
104
+ for container in death.containers:
105
+ death.bar_label(container)
106
+ st.pyplot(fig)
107
+ with st.expander("See explanation"):
108
+ st.write('''
109
+ Based on the diagram above, we can see that more man patients die than woman patients.
110
+ ''')
111
+
112
+ # Bar Plot 2
113
+ st.write('#### Plot Death Event Based on Smoking')
114
+ fig = plt.figure(figsize=(15, 5))
115
+ smoking = sns.countplot(data=data, x="smoking", hue="DEATH_EVENT")
116
+ for container in smoking.containers:
117
+ smoking.bar_label(container)
118
+ st.pyplot(fig)
119
+ with st.expander("See explanation"):
120
+ st.write('''
121
+ Based on the diagram above, we can see that the number of patients who do not smoke and die is equal to the number of patients who smoke and do not die.
122
+ ''')
123
+
124
+ # Bar Plot 3
125
+ st.write('#### Plot Death Event Based on Anaemia')
126
+ fig = plt.figure(figsize=(15, 5))
127
+ anaemia = sns.countplot(data=data, x="anaemia", hue="DEATH_EVENT")
128
+ for container in anaemia.containers:
129
+ anaemia.bar_label(container)
130
+ st.pyplot(fig)
131
+ with st.expander("See explanation"):
132
+ st.write('''
133
+ Based on the diagram above, we can see that patients who do not die with non-anaemia are more than patients who die with anaemia.
134
+ ''')
135
+
136
+ # Bar Plot 4
137
+ st.write('#### Plot Death Event Based on Diabetes')
138
+ fig = plt.figure(figsize=(15, 5))
139
+ diabetes = sns.countplot(data=data, x="diabetes", hue="DEATH_EVENT")
140
+ for container in diabetes.containers:
141
+ diabetes.bar_label(container)
142
+ st.pyplot(fig)
143
+ with st.expander("See explanation"):
144
+ st.write('''
145
+ Based on the diagram above, we can see that patients who do not die with non-diabetics are more than patients who die with diabetes.
146
+ ''')
147
+
148
+ # Bar Plot 5
149
+ st.write('#### Plot Death Event Based on High Blood Pressure')
150
+ fig = plt.figure(figsize=(15, 5))
151
+ hbp = sns.countplot(data=data, x="high_blood_pressure", hue="DEATH_EVENT")
152
+ for container in hbp.containers:
153
+ hbp.bar_label(container)
154
+ st.pyplot(fig)
155
+ with st.expander("See explanation"):
156
+ st.write('''
157
+ Based on the diagram above, we can see that patients who do not die with non-high blood pressure are more than patients who die with high blood pressure.
158
+ ''')
159
+
160
+ if __name__ == '__main__':
161
+ run()
h8dsft_P1G3_theo.csv ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ age,anaemia,creatinine_phosphokinase,diabetes,ejection_fraction,high_blood_pressure,platelets,serum_creatinine,serum_sodium,sex,smoking,time,DEATH_EVENT
2
+ 42,1,250,1,15,0,213000,1.3,136,0,0,65,1
3
+ 46,0,168,1,17,1,271000,2.1,124,0,0,100,1
4
+ 65,1,160,1,20,0,327000,2.7,116,0,0,8,1
5
+ 53,1,91,0,20,1,418000,1.4,139,0,0,43,1
6
+ 50,1,582,1,20,1,279000,1,134,0,0,186,0
7
+ 70,1,125,0,25,1,237000,1,140,0,0,15,1
8
+ 65,1,52,0,25,1,276000,1.3,137,0,0,16,0
9
+ 70,0,161,0,25,0,244000,1.2,142,0,0,66,1
10
+ 60,1,76,1,25,0,196000,2.5,132,0,0,77,1
11
+ 59,1,280,1,25,1,302000,1,141,0,0,78,1
12
+ 60,1,156,1,25,1,318000,1.2,137,0,0,85,0
13
+ 60,0,1896,1,25,0,365000,2.1,144,0,0,172,1
14
+ 65,0,56,0,25,0,237000,5,130,0,0,207,0
15
+ 72,0,211,0,25,0,274000,1.2,134,0,0,207,0
16
+ 49,1,80,0,30,1,427000,1,138,0,0,12,0
17
+ 65,1,128,1,30,1,297000,1.6,136,0,0,20,1
18
+ 75,0,582,1,30,1,263358.03,1.83,134,0,0,23,1
19
+ 50,1,159,1,30,0,302000,1.2,138,0,0,29,0
20
+ 50,0,124,1,30,1,153000,1.2,136,0,1,32,1
21
+ 57,1,129,0,30,0,395000,1,140,0,0,42,1
22
+ 72,1,328,0,30,1,621000,1.7,138,0,1,88,1
23
+ 60,1,582,0,30,1,127000,0.9,145,0,0,95,0
24
+ 50,0,482,1,30,0,329000,0.9,132,0,0,109,0
25
+ 65,0,167,0,30,0,259000,0.8,138,0,0,186,0
26
+ 48,1,131,1,30,1,244000,1.6,130,0,0,193,1
27
+ 60,0,166,0,30,0,62000,1.7,127,0,0,207,1
28
+ 50,0,2522,0,30,1,404000,0.5,139,0,0,214,0
29
+ 50,1,1051,1,30,0,232000,0.7,136,0,0,246,0
30
+ 50,1,249,1,35,1,319000,1,128,0,0,28,1
31
+ 62,0,281,1,35,0,221000,1,136,0,0,108,0
32
+ 46,1,291,0,35,0,348000,0.9,140,0,0,109,0
33
+ 65,1,335,0,35,1,235000,0.8,136,0,0,120,0
34
+ 52,1,58,0,35,0,277000,1.4,136,0,0,120,0
35
+ 50,1,2334,1,35,0,75000,0.9,142,0,0,126,1
36
+ 70,0,835,0,35,1,305000,0.8,133,0,0,145,0
37
+ 49,0,972,1,35,1,268000,0.8,130,0,0,187,0
38
+ 55,0,582,1,35,1,371000,0.7,140,0,0,197,0
39
+ 70,0,81,1,35,1,533000,1.3,139,0,0,212,0
40
+ 55,0,572,1,35,0,231000,0.8,143,0,0,215,0
41
+ 70,0,88,1,35,1,236000,1.2,132,0,0,215,0
42
+ 70,0,618,0,35,0,327000,1.1,142,0,0,245,0
43
+ 65,0,892,1,35,0,263358.03,1.1,142,0,0,256,0
44
+ 60,0,235,1,38,0,329000,3,142,0,0,30,1
45
+ 60,1,260,1,38,0,255000,2.2,132,0,1,45,1
46
+ 58,0,144,1,38,1,327000,0.7,142,0,0,83,0
47
+ 86,0,582,0,38,0,263358.03,1.83,134,0,0,95,1
48
+ 66,1,68,1,38,1,162000,1,136,0,0,95,0
49
+ 60,0,96,1,38,0,228000,0.75,140,0,0,95,0
50
+ 80,0,776,1,38,1,192000,1.3,135,0,0,130,1
51
+ 45,0,582,1,38,1,263358.03,1.18,137,0,0,185,0
52
+ 65,0,326,0,38,0,294000,1.7,139,0,0,220,0
53
+ 45,0,582,1,38,0,302000,0.9,140,0,0,244,0
54
+ 67,0,213,0,38,0,215000,1.2,133,0,0,245,0
55
+ 45,0,582,0,38,1,422000,0.8,137,0,0,245,0
56
+ 55,0,84,1,38,0,451000,1.3,136,0,0,246,0
57
+ 90,1,337,0,38,0,390000,0.9,144,0,0,256,0
58
+ 55,0,1820,0,38,0,270000,1.2,139,0,0,271,0
59
+ 95,1,112,0,40,1,196000,1,138,0,0,24,1
60
+ 50,0,318,0,40,1,216000,2.3,131,0,0,60,1
61
+ 70,0,69,0,40,0,293000,1.7,136,0,0,75,0
62
+ 63,1,61,1,40,0,221000,1.1,140,0,0,86,0
63
+ 58,1,400,0,40,0,164000,1,139,0,0,91,0
64
+ 46,0,719,0,40,1,263358.03,1.18,137,0,0,107,0
65
+ 61,1,84,0,40,1,229000,0.9,141,0,0,110,0
66
+ 65,0,582,1,40,0,270000,1,138,0,0,140,0
67
+ 60.667,1,151,1,40,1,201000,1,136,0,0,172,0
68
+ 40,1,101,0,40,0,226000,0.8,141,0,0,187,0
69
+ 60,1,2281,1,40,0,283000,1,141,0,0,187,0
70
+ 65,1,720,1,40,0,257000,1,136,0,0,210,0
71
+ 73,1,1185,0,40,1,220000,0.9,141,0,0,213,0
72
+ 53,0,207,1,40,0,223000,1.2,130,0,0,214,0
73
+ 62,1,655,0,40,0,283000,0.7,133,0,0,233,0
74
+ 51,0,582,1,40,0,221000,0.9,134,0,0,244,0
75
+ 55,0,336,0,45,1,324000,0.9,140,0,0,74,0
76
+ 72,0,233,0,45,1,235000,2.5,135,0,0,115,1
77
+ 40,0,244,0,45,1,275000,0.9,140,0,0,174,0
78
+ 50,1,167,1,45,0,362000,1,136,0,0,187,0
79
+ 82,1,855,1,50,1,321000,1,145,0,0,30,1
80
+ 70,1,69,1,50,1,351000,1,134,0,0,44,1
81
+ 60,0,53,0,50,1,286000,2.3,143,0,0,87,0
82
+ 43,1,358,0,50,0,237000,1.3,135,0,0,97,0
83
+ 49,1,69,0,50,0,132000,1,140,0,0,147,0
84
+ 50,0,582,0,50,0,153000,0.6,134,0,0,172,1
85
+ 70,0,1202,0,50,1,358000,0.9,141,0,0,196,0
86
+ 48,1,582,1,55,0,87000,1.9,121,0,0,15,1
87
+ 45,0,582,1,55,0,543000,1,132,0,0,250,0
88
+ 45,0,615,1,55,0,222000,0.8,141,0,0,257,0
89
+ 60,1,588,1,60,0,194000,1.1,142,0,0,33,1
90
+ 70,0,92,0,60,1,317000,0.8,140,0,1,74,0
91
+ 42,0,582,0,60,0,263358.03,1.18,137,0,0,82,0
92
+ 70,1,59,0,60,0,255000,1.1,136,0,0,85,0
93
+ 70,1,143,0,60,0,351000,1.3,137,0,0,90,1
94
+ 60,1,96,1,60,1,271000,0.7,136,0,0,94,0
95
+ 85,1,102,0,60,0,507000,3.2,138,0,0,94,0
96
+ 65,1,113,1,60,1,203000,0.9,140,0,0,94,0
97
+ 58,1,200,1,60,0,300000,0.8,137,0,0,104,0
98
+ 65,1,59,1,60,0,172000,0.9,137,0,0,107,0
99
+ 64,1,62,0,60,0,309000,1.5,135,0,0,174,0
100
+ 75,0,675,1,60,0,265000,1.4,125,0,0,205,0
101
+ 68,1,157,1,60,0,208000,1,140,0,0,237,0
102
+ 45,0,2060,1,60,0,742000,0.8,138,0,0,278,0
103
+ 60,0,3964,1,62,0,263358.03,6.8,146,0,0,43,1
104
+ 65,0,157,0,65,0,263358.03,1.5,138,0,0,10,1
105
+ 54,1,427,0,70,1,151000,9,137,0,0,196,1
106
+ 45,0,582,0,80,0,263358.03,1.18,137,0,0,63,0
107
+ 45,0,582,0,14,0,166000,0.8,127,1,0,14,1
108
+ 75,1,246,0,15,0,127000,1.2,137,1,0,10,1
109
+ 70,0,212,1,17,1,389000,1,136,1,1,188,0
110
+ 75,0,582,0,20,1,265000,1.9,130,1,0,4,1
111
+ 65,0,146,0,20,0,162000,1.3,129,1,1,7,1
112
+ 50,1,111,0,20,0,210000,1.9,137,1,0,7,1
113
+ 70,0,582,0,20,1,263358.03,1.83,134,1,1,31,1
114
+ 80,1,553,0,20,1,140000,4.4,133,1,0,41,1
115
+ 49,0,789,0,20,1,319000,1.1,136,1,1,55,1
116
+ 72,0,364,1,20,1,254000,1.3,136,1,1,59,1
117
+ 60,0,68,0,20,0,119000,2.9,127,1,1,64,1
118
+ 69,0,582,0,20,0,266000,1.2,134,1,1,73,1
119
+ 60,1,47,0,20,0,204000,0.7,139,1,1,73,1
120
+ 59,0,66,1,20,0,70000,2.4,134,1,0,135,1
121
+ 50,1,115,0,20,0,189000,0.8,139,1,0,146,0
122
+ 45,0,582,0,20,1,126000,1.6,135,1,0,180,1
123
+ 73,0,582,0,20,0,263358.03,1.83,134,1,0,198,1
124
+ 55,0,1199,0,20,0,263358.03,1.83,134,1,1,241,1
125
+ 62,0,231,0,25,1,253000,0.9,140,1,1,10,1
126
+ 51,0,1380,0,25,1,271000,0.9,130,1,0,38,1
127
+ 68,1,577,0,25,1,166000,1,138,1,0,43,1
128
+ 45,0,7702,1,25,1,390000,1,139,1,0,60,1
129
+ 72,1,110,0,25,0,274000,1,140,1,1,65,1
130
+ 65,0,113,1,25,0,497000,1.83,135,1,0,67,1
131
+ 57,1,115,0,25,1,181000,1.1,144,1,0,79,0
132
+ 60,1,154,0,25,0,210000,1.7,135,1,0,82,1
133
+ 63,1,514,1,25,1,254000,1.3,134,1,0,83,0
134
+ 65,1,305,0,25,0,298000,1.1,141,1,0,87,0
135
+ 80,0,898,0,25,0,149000,1.1,144,1,1,87,0
136
+ 50,0,369,1,25,0,252000,1.6,136,1,0,90,0
137
+ 68,1,646,0,25,0,305000,2.1,130,1,0,108,0
138
+ 72,1,943,0,25,1,338000,1.7,139,1,1,111,1
139
+ 60,1,231,1,25,0,194000,1.7,140,1,0,120,0
140
+ 50,0,250,0,25,0,262000,1,136,1,1,120,0
141
+ 59,1,176,1,25,0,221000,1,136,1,1,150,1
142
+ 65,0,395,1,25,0,265000,1.2,136,1,1,154,1
143
+ 58,1,145,0,25,0,219000,1.2,137,1,1,170,1
144
+ 60,0,59,0,25,1,212000,3.5,136,1,1,187,0
145
+ 47,0,582,0,25,0,130000,0.8,134,1,0,201,0
146
+ 58,0,582,1,25,0,504000,1,138,1,0,205,0
147
+ 58,1,57,0,25,0,189000,1.3,132,1,1,205,0
148
+ 55,0,2017,0,25,0,314000,1.1,138,1,0,214,1
149
+ 64,0,143,0,25,0,246000,2.4,135,1,0,214,0
150
+ 45,1,66,1,25,0,233000,0.8,135,1,0,230,0
151
+ 65,1,258,1,25,0,198000,1.4,129,1,0,235,1
152
+ 45,1,981,0,30,0,136000,1.1,137,1,0,11,1
153
+ 82,0,70,1,30,0,200000,1.2,132,1,1,26,1
154
+ 60,0,2656,1,30,0,305000,2.3,137,1,0,30,0
155
+ 95,1,371,0,30,0,461000,2,132,1,0,50,1
156
+ 42,0,5209,0,30,0,226000,1,140,1,1,87,0
157
+ 61,0,248,0,30,1,267000,0.7,136,1,1,104,0
158
+ 50,0,1548,0,30,1,211000,0.8,138,1,0,108,0
159
+ 50,0,185,0,30,0,266000,0.7,141,1,1,112,0
160
+ 52,0,132,0,30,0,218000,0.7,136,1,1,112,0
161
+ 75,1,582,0,30,0,225000,1.83,134,1,0,113,1
162
+ 45,0,2442,1,30,0,334000,1.1,139,1,0,129,1
163
+ 40,0,478,1,30,0,303000,0.9,136,1,0,148,0
164
+ 60.667,1,104,1,30,0,389000,1.5,136,1,0,171,1
165
+ 73,1,231,1,30,0,160000,1.18,142,1,1,180,0
166
+ 70,0,232,0,30,0,173000,1.2,132,1,0,210,0
167
+ 65,0,582,1,30,0,249000,1.3,136,1,1,212,0
168
+ 52,1,191,1,30,1,334000,1,142,1,1,216,0
169
+ 44,0,582,1,30,1,263358.03,1.6,130,1,1,244,0
170
+ 60,1,257,1,30,0,150000,1,137,1,1,245,0
171
+ 42,0,64,0,30,0,215000,3.8,128,1,1,250,0
172
+ 80,1,123,0,35,1,388000,9.4,133,1,1,10,1
173
+ 68,1,220,0,35,1,289000,0.9,140,1,1,20,1
174
+ 69,0,582,1,35,0,228000,3.5,134,1,0,30,1
175
+ 70,1,75,0,35,0,223000,2.7,138,1,1,54,0
176
+ 55,0,109,0,35,0,254000,1.1,139,1,1,60,0
177
+ 45,0,582,0,35,0,385000,1,145,1,0,61,1
178
+ 58,0,582,1,35,0,122000,0.9,139,1,1,71,0
179
+ 85,0,5882,0,35,0,243000,1,132,1,1,72,1
180
+ 55,0,47,0,35,1,173000,1.1,137,1,0,79,0
181
+ 45,1,1876,1,35,0,226000,0.9,138,1,0,88,0
182
+ 45,0,292,1,35,0,850000,1.3,142,1,1,88,0
183
+ 55,0,60,0,35,0,228000,1.2,135,1,1,90,0
184
+ 53,1,270,1,35,0,227000,3.4,145,1,0,105,0
185
+ 81,0,4540,0,35,0,231000,1.18,137,1,1,107,0
186
+ 60,0,2261,0,35,1,228000,0.9,136,1,0,115,0
187
+ 50,0,1846,1,35,0,263358.03,1.18,137,1,1,119,0
188
+ 45,1,130,0,35,0,174000,0.8,139,1,1,121,0
189
+ 51,1,582,1,35,0,263358.03,1.5,136,1,1,145,0
190
+ 65,0,198,1,35,1,281000,0.9,137,1,1,146,0
191
+ 80,0,582,1,35,0,350000,2.1,134,1,0,174,0
192
+ 60,0,1211,1,35,0,263358.03,1.8,113,1,1,186,0
193
+ 65,1,135,0,35,1,290000,0.8,134,1,0,194,0
194
+ 73,0,582,0,35,1,203000,1.3,134,1,0,195,0
195
+ 68,1,1021,1,35,0,271000,1.1,134,1,0,197,0
196
+ 42,1,86,0,35,0,365000,1.1,139,1,1,201,0
197
+ 55,1,2794,0,35,1,141000,1,140,1,0,206,0
198
+ 70,0,93,0,35,0,185000,1.1,134,1,1,208,0
199
+ 40,1,129,0,35,0,255000,0.9,137,1,0,209,0
200
+ 40,0,90,0,35,0,255000,1.1,136,1,1,212,0
201
+ 40,0,624,0,35,0,301000,1,142,1,1,214,0
202
+ 50,1,298,0,35,0,362000,0.9,140,1,1,240,0
203
+ 40,0,582,1,35,0,222000,1,132,1,0,244,0
204
+ 60,0,253,0,35,0,279000,1.7,140,1,0,250,0
205
+ 60,0,320,0,35,0,133000,1.4,139,1,0,258,0
206
+ 63,1,103,1,35,0,179000,0.9,136,1,1,270,0
207
+ 55,0,7861,0,38,0,263358.03,1.1,136,1,0,6,1
208
+ 75,1,81,0,38,1,368000,4,131,1,1,10,1
209
+ 50,1,168,0,38,1,276000,1.1,137,1,0,11,1
210
+ 87,1,149,0,38,0,262000,0.9,140,1,0,14,1
211
+ 80,0,148,1,38,0,149000,1.9,144,1,1,23,1
212
+ 58,1,60,0,38,0,153000,5.8,134,1,0,26,1
213
+ 94,0,582,1,38,1,263358.03,1.83,134,1,0,27,1
214
+ 50,0,582,1,38,0,310000,1.9,135,1,1,35,1
215
+ 60,0,582,1,38,1,451000,0.6,138,1,1,40,1
216
+ 75,1,203,1,38,1,283000,0.6,131,1,1,74,0
217
+ 63,0,936,0,38,0,304000,1.1,133,1,1,88,0
218
+ 80,0,805,0,38,0,263358.03,1.1,134,1,0,109,1
219
+ 75,0,99,0,38,1,224000,2.5,134,1,0,162,1
220
+ 85,0,212,0,38,0,186000,0.9,136,1,0,187,0
221
+ 53,1,707,0,38,0,330000,1.4,137,1,1,209,0
222
+ 54,0,582,1,38,0,264000,1.8,134,1,0,213,0
223
+ 61,1,80,1,38,0,282000,1.4,137,1,0,213,0
224
+ 58,0,132,1,38,1,253000,1,139,1,0,230,0
225
+ 61,0,582,1,38,0,147000,1.2,141,1,0,237,0
226
+ 56,1,135,1,38,0,133000,1.7,140,1,0,244,0
227
+ 70,0,582,1,38,0,25100,1.1,140,1,0,246,0
228
+ 65,0,1688,0,38,0,263358.03,1.1,138,1,1,250,0
229
+ 52,0,190,1,38,0,382000,1,140,1,1,258,0
230
+ 62,0,61,1,38,1,155000,1.1,143,1,1,270,0
231
+ 45,0,2413,0,38,0,140000,1.4,140,1,1,280,0
232
+ 90,1,47,0,40,1,204000,2.1,132,1,1,8,1
233
+ 60,1,607,0,40,0,216000,0.6,138,1,1,54,0
234
+ 41,0,148,0,40,0,374000,0.8,140,1,1,68,0
235
+ 42,0,102,1,40,0,237000,1.2,140,1,0,74,0
236
+ 44,0,84,1,40,1,235000,0.7,139,1,0,79,0
237
+ 60,1,754,1,40,1,328000,1.2,126,1,0,91,0
238
+ 60,0,582,0,40,0,217000,3.7,134,1,0,96,1
239
+ 75,0,582,0,40,0,263358.03,1.18,137,1,0,107,0
240
+ 66,1,72,0,40,1,242000,1.2,134,1,0,121,0
241
+ 63,1,582,0,40,0,448000,0.9,137,1,1,123,0
242
+ 52,0,3966,0,40,0,325000,0.9,140,1,1,146,0
243
+ 69,0,1419,0,40,0,105000,1,135,1,1,147,0
244
+ 55,0,835,0,40,0,279000,0.7,140,1,1,147,0
245
+ 50,1,121,1,40,0,260000,0.7,130,1,0,175,0
246
+ 78,1,64,0,40,0,277000,0.7,137,1,1,187,0
247
+ 55,0,66,0,40,0,203000,1,138,1,0,233,0
248
+ 42,0,64,0,40,0,189000,0.7,140,1,0,245,0
249
+ 70,0,2695,1,40,0,241000,1,137,1,0,247,0
250
+ 70,0,582,0,40,0,51000,2.7,136,1,1,250,0
251
+ 50,1,54,0,40,0,279000,0.8,141,1,0,250,0
252
+ 55,1,170,1,40,0,336000,1.2,135,1,0,250,0
253
+ 70,0,122,1,45,1,284000,1.3,136,1,1,26,1
254
+ 85,0,23,0,45,0,360000,3,132,1,0,28,1
255
+ 70,0,571,1,45,1,185000,1.2,139,1,1,33,1
256
+ 70,0,66,1,45,0,249000,0.8,136,1,1,80,0
257
+ 60,0,897,1,45,0,297000,1,133,1,0,80,0
258
+ 75,0,582,0,45,1,263358.03,1.18,137,1,0,87,0
259
+ 55,0,748,0,45,0,263000,1.3,137,1,0,88,0
260
+ 60,1,1082,1,45,0,250000,6.1,131,1,0,107,0
261
+ 50,0,115,0,45,1,184000,0.9,134,1,1,118,0
262
+ 59,1,129,0,45,1,362000,1.1,139,1,1,121,0
263
+ 77,1,418,0,45,0,223000,1.8,145,1,0,180,1
264
+ 63,1,1767,0,45,0,73000,0.7,137,1,0,186,0
265
+ 53,1,582,0,45,0,305000,1.1,137,1,1,209,0
266
+ 55,1,180,0,45,0,263358.03,1.18,137,1,1,211,0
267
+ 50,0,245,0,45,1,274000,1,133,1,0,215,0
268
+ 50,0,196,0,45,0,395000,1.6,136,1,1,285,0
269
+ 82,1,379,0,50,0,47000,1.3,136,1,0,13,1
270
+ 65,0,94,1,50,1,188000,1,140,1,0,29,1
271
+ 90,1,60,1,50,0,226000,1,134,1,0,30,1
272
+ 72,0,127,1,50,1,218000,1,134,1,0,33,0
273
+ 65,0,224,1,50,0,149000,1.3,137,1,1,72,0
274
+ 67,0,582,0,50,0,263358.03,1.18,137,1,1,76,0
275
+ 79,1,55,0,50,1,172000,1.8,133,1,0,78,0
276
+ 51,0,78,0,50,0,406000,0.7,140,1,0,79,0
277
+ 85,1,910,0,50,0,235000,1.3,134,1,0,121,0
278
+ 78,0,224,0,50,0,481000,1.4,138,1,1,192,0
279
+ 65,0,118,0,50,0,194000,1.1,145,1,1,200,0
280
+ 77,1,109,0,50,1,406000,1.1,137,1,0,209,0
281
+ 75,0,119,0,50,1,248000,1.1,148,1,0,209,0
282
+ 53,0,56,0,50,0,308000,0.7,135,1,1,231,0
283
+ 60,1,315,1,60,0,454000,1.1,131,1,1,10,1
284
+ 53,0,63,1,60,0,368000,0.8,135,1,0,22,0
285
+ 65,1,68,1,60,1,304000,0.8,140,1,0,79,0
286
+ 58,1,133,0,60,1,219000,1,141,1,0,83,0
287
+ 85,0,129,0,60,0,306000,1.2,132,1,1,90,1
288
+ 60,1,737,0,60,1,210000,1.5,135,1,1,95,0
289
+ 53,1,1808,0,60,1,249000,0.7,138,1,1,106,0
290
+ 63,0,193,0,60,1,295000,1.3,145,1,1,107,0
291
+ 64,0,1610,0,60,0,242000,1,137,1,0,113,0
292
+ 62,0,30,1,60,1,244000,0.9,139,1,0,117,0
293
+ 53,0,196,0,60,0,220000,0.7,133,1,1,134,0
294
+ 70,1,171,0,60,1,176000,1.1,145,1,1,146,0
295
+ 60,1,95,0,60,0,337000,1,138,1,1,146,0
296
+ 63,1,122,1,60,0,267000,1.2,145,1,0,147,0
297
+ 45,0,308,1,60,1,377000,1,136,1,0,186,0
298
+ 70,0,97,0,60,1,220000,0.9,138,1,0,186,0
299
+ 53,1,446,0,60,1,263358.03,1,139,1,0,215,0
300
+ 50,0,582,0,62,1,147000,0.8,140,1,1,192,0
list_num_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["age", "ejection_fraction", "serum_creatinine", "serum_sodium", "time"]
model_gbc.pkl ADDED
Binary file (112 kB). View file
 
model_rfc.pkl ADDED
Binary file (509 kB). View file
 
model_scaler.pkl ADDED
Binary file (723 Bytes). View file
 
prediction.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import json
6
+
7
+ # Load all files
8
+
9
+ with open('list_num_cols.txt', 'r') as file_1:
10
+ list_num_cols = json.load(file_1)
11
+
12
+ with open('model_scaler.pkl', 'rb') as file_2:
13
+ scaler = pickle.load(file_2)
14
+
15
+ with open('model_rfc.pkl', 'rb') as file_3:
16
+ model_rfc = pickle.load(file_3)
17
+
18
+ with open('model_gbc.pkl', 'rb') as file_4:
19
+ model_gbc = pickle.load(file_4)
20
+
21
+ def run():
22
+ st.write('##### Form Prediction of Death Due To Heart Failure')
23
+ # Making Form
24
+ with st.form(key='Form Form Prediction of Death Due To Heart Failure'):
25
+ age = st.number_input('age', min_value=30, max_value=90, value=30)
26
+ anaemia = st.selectbox('anaemia', (0,1), index=0, help='0=No, 1=Yes | Decrease of red blood cells or hemogrobin.')
27
+ creatinine_phosphokinase = st.number_input('creatinine_phosphokinase', min_value=50, max_value=6000, value=50, step=1, help='Level of the CPK enzyme in the blood (mcg/L).')
28
+ diabetes = st.selectbox('diabetes', (0,1), index=0, help='0=No, 1=Yes | If the patient has diabetes.')
29
+ ejection_fraction = st.number_input('ejection_fraction', min_value=1, max_value=100, value=1, help='Percentage of blood leaving the heart at each contraction (percentage).')
30
+ high_blood_pressure = st.selectbox('high_blood_pressure', (0,1), index=0, help='0=No, 1=Yes | If the patient has hypertention.')
31
+ platelets = st.number_input('platelets', min_value=40000, max_value=500000, value=40000, help='Platelets in the blood (kiloplatelets/mL).')
32
+ serum_creatinine = st.number_input('serum_creatinine', min_value=0, max_value=10, value=0, help='Level of serum creatinine in the blood (mg/dL).')
33
+ serum_sodium = st.number_input('serum_sodium', min_value=100, max_value=150, value=100, help='Level of serum sodium in the blood (mEq/L).')
34
+ sex = st.selectbox('sex', (0,1), index=0, help='0=Woman, 1=Man')
35
+ smoking = st.selectbox('smoking', (0,1), index=0, help='0=No, 1=Yes | If the patient smokes or not.')
36
+ time = st.number_input('time', min_value=1, max_value=300, value=1, help='Follow-up period (days).')
37
+ st.markdown('---')
38
+
39
+ submited_1 = st.form_submit_button('Predict using RFC')
40
+ submited_2 = st.form_submit_button('Predict using GBC')
41
+
42
+ data_inf = {
43
+ 'age' : age,
44
+ 'anaemia' : anaemia,
45
+ 'creatinine_phosphokinase' : creatinine_phosphokinase,
46
+ 'diabetes' : diabetes,
47
+ 'ejection_fraction' : ejection_fraction,
48
+ 'high_blood_pressure' : high_blood_pressure,
49
+ 'platelets' : platelets,
50
+ 'serum_creatinine' : serum_creatinine,
51
+ 'serum_sodium' : serum_sodium,
52
+ 'sex' : sex,
53
+ 'smoking' : smoking,
54
+ 'time' : time,
55
+ }
56
+
57
+ data_inf = pd.DataFrame([data_inf])
58
+ st.dataframe(data_inf)
59
+
60
+ if submited_1:
61
+ # Split between numerical columns and categorical columns
62
+ data_inf_num = data_inf[list_num_cols]
63
+ data_inf_num
64
+ #Feature scaling and feature encoding
65
+ data_inf_num_scaled = scaler.transform(data_inf_num)
66
+ data_inf_final = data_inf_num_scaled
67
+ #Predict using Random Forest Classification
68
+ y_pred_inf = model_rfc.predict(data_inf_final)
69
+ st.write('# Result Prediction using RFC : ', str(int(y_pred_inf)))
70
+ else:
71
+ # Split between numerical columns and categorical columns
72
+ data_inf_num = data_inf[list_num_cols]
73
+ data_inf_num
74
+ #Feature scaling and feature encoding
75
+ data_inf_num_scaled = scaler.transform(data_inf_num)
76
+ data_inf_final = data_inf_num_scaled
77
+ #Predict using RFC
78
+ y_pred_inf = model_gbc.predict(data_inf_final)
79
+ st.write('# Result Prediction using GBC : ', str(int(y_pred_inf)))
80
+
81
+ if __name__ == '__main__':
82
+ run()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ Pillow
6
+ numpy
7
+ scikit-learn==1.2.2
8
+ plotly
9
+ streamlit_option_menu