mukhlishr commited on
Commit
061961e
1 Parent(s): e12f617

Upload 8 files

Browse files
Files changed (7) hide show
  1. app.py +11 -0
  2. eda.py +50 -0
  3. gbc_model.pkl +3 -0
  4. hearth attack.jpg +0 -0
  5. prediction.py +70 -0
  6. requirements.txt +8 -0
  7. scaler.pkl +3 -0
app.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ navigation = st.sidebar.selectbox('pilih halaman : ', ('EDA', 'Predict of Death'))
6
+
7
+ if navigation == 'EDA':
8
+ eda.run()
9
+
10
+ else:
11
+ prediction.run()
eda.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # untuk lebarkan layout setelah import
9
+ st.set_page_config(
10
+ page_title = 'Hearth Failure',
11
+ layout = 'wide',
12
+ initial_sidebar_state='expanded'
13
+ )
14
+
15
+ def run():
16
+
17
+ # Membuat file
18
+ st.title( 'Death Prediction : Hearth Failure')
19
+
20
+ # Membuat sub header
21
+ st.subheader('EDA Hearth Failure')
22
+
23
+ # Menambahkan gambar
24
+ image = Image.open('hearth attack.jpg')
25
+ st.image(image, caption='Hearth Failure')
26
+
27
+ # Menambahkan deskripsi
28
+ st.write('Page ini merupakan hasil EDA dari dataset Hearth Failure')
29
+
30
+
31
+ # show data frame
32
+ df = pd.read_csv('https://raw.githubusercontent.com/mukhlishr/rasyidi/main/h8dsft_P1G3_mukhlish_rasyidi.csv')
33
+ st.dataframe(df)
34
+
35
+ # Membuat Barplot
36
+ st.write('###### Plot Death Event')
37
+ fig=plt.figure(figsize=(15,5))
38
+ sns.countplot(x='DEATH_EVENT', data = df)
39
+ st.pyplot(fig)
40
+
41
+ # Membuat histogram
42
+ st.write('##### Histogram of Age')
43
+ fig = plt.figure(figsize=(15,5))
44
+ sns.histplot(df['age'], bins=30, kde=True)
45
+ st.pyplot(fig)
46
+
47
+
48
+
49
+ if __name__ == '__main__':
50
+ run()
gbc_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2503e18457402e9f89f3d04f7f92aafba07110c6e24c2a1200cc7d251ea63fe4
3
+ size 117364
hearth attack.jpg ADDED
prediction.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ import pickle
6
+ import json
7
+
8
+
9
+ # Load All Files
10
+
11
+ with open('gbc_model.pkl', 'rb') as file_1:
12
+ gbc_model = pickle.load(file_1)
13
+
14
+ with open('scaler.pkl', 'rb') as file_2:
15
+ scaler = pickle.load(file_2)
16
+
17
+
18
+ # bikin fungsi
19
+ def run():
20
+
21
+ with st.form(key='patient_condition'):
22
+ anemia = st.selectbox('Anemia', (0, 1), index=1)
23
+ diabetes = st.selectbox('Diabetes', (0, 1), index=1)
24
+ high_blood_pressure = st.selectbox('High blood pressure', (0, 1), index=1)
25
+ serum_sodium = st.number_input('Serum Sodium', min_value=100, max_value=150, value=100)
26
+ sex = st.selectbox('Sex', (0, 1), index=1)
27
+ smoking = st.selectbox('Sex', (0, 1), index=1)
28
+ time = st.number_input('Time', min_value=100, max_value=150, value=100)
29
+ binned_age = st.selectbox('Range of age', (1, 2,3,4), index=1)
30
+ binned_creat_serum = st.selectbox('High serum creatinine', (1, 2), index=1)
31
+ binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1)
32
+ binned_ejection = st.selectbox(' Ejection frraction', (1,2,3), index=1)
33
+ binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1)
34
+ binned_platelets = st.selectbox('Platelets count', (0, 1, 2), index=1)
35
+ st.markdown('---')
36
+
37
+ submitted = st.form_submit_button('Predict')
38
+
39
+ data_inf = {
40
+ 'anemia': 1,
41
+ 'diabetes': 1,
42
+ 'high_blood_pressure' : 1,
43
+ 'serum_sodium': 130,
44
+ 'sex': 1,
45
+ 'smoking': 1,
46
+ 'time': 150,
47
+ 'binned_age': 3,
48
+ 'binned_creat_serum' : 2,
49
+ 'binned_cpk' : 2,
50
+ 'binned_ejection' : 2,
51
+ 'binned_platelets': 2
52
+ }
53
+
54
+ data_inf = pd.DataFrame([data_inf])
55
+ st.dataframe(data_inf)
56
+
57
+ if submitted:
58
+
59
+ # Feature Scaling and Feature Encoding
60
+ col_headers = list(data_inf.columns.values)
61
+ data_inf_scaled = scaler.transform(data_inf)
62
+ data_inf_df = pd.DataFrame(data_inf_scaled, columns=col_headers)
63
+
64
+
65
+ # Predict using gbc
66
+ y_pred_inf = gbc_model.predict(data_inf_df)
67
+ st.write('# Rating: ', str(int(y_pred_inf)))
68
+
69
+ if __name__ == '__main__':
70
+ run()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # daftar library yang dibutuhkan semua
2
+ streamlit
3
+ pandas
4
+ seaborn
5
+ matplotlib
6
+ numpy
7
+ scikit-learn==1.2.1
8
+ plotly
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec5fb5bd0c630066544195baaebb1c4e174fcd7c8eb816c6ad7a5371d8274803
3
+ size 988