Spaces:
Runtime error
Runtime error
Azrieldr
commited on
Commit
•
bad6720
1
Parent(s):
acda498
new
Browse files- GB.pkl +3 -0
- app.py +10 -0
- eda.py +43 -0
- image.png +0 -0
- prediction.py +83 -0
- requirements.txt +8 -0
- rf.pkl +3 -0
- scaler.pkl +3 -0
GB.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2744b091607469ff490b0c9e81fbb65bbcc226264d94e417467fd9e1dc382422
|
3 |
+
size 11540004
|
app.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import prediction
|
3 |
+
import eda
|
4 |
+
|
5 |
+
navigation = st.sidebar.selectbox('Pilih Halaman: ', ('Predict', 'EDA'))
|
6 |
+
|
7 |
+
if navigation == 'Predict':
|
8 |
+
prediction.run()
|
9 |
+
else:
|
10 |
+
eda.run()
|
eda.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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= 'Prediksi Serangan Jantung',
|
10 |
+
layout='wide',
|
11 |
+
initial_sidebar_state='expanded'
|
12 |
+
)
|
13 |
+
|
14 |
+
def run():
|
15 |
+
image = Image.open('image.png')
|
16 |
+
resized_image = image.resize((300, 300))
|
17 |
+
st.image(resized_image, caption='Serangan jantung')
|
18 |
+
|
19 |
+
st.title('Prediksi Serangan Jantung')
|
20 |
+
df = pd.read_csv('https://raw.githubusercontent.com/Azrieldr/latihan/master/h8dsft_P1G3_Azrieldr.csv')
|
21 |
+
st.dataframe(df)
|
22 |
+
|
23 |
+
|
24 |
+
persentaseKematian = df['DEATH_EVENT'].mean()*100
|
25 |
+
# Create pie chart
|
26 |
+
fig, ax = plt.subplots(figsize=(10,15), dpi=100)
|
27 |
+
ax.pie([persentaseKematian, 100-persentaseKematian], labels=['Meninggal', 'Selamat'], autopct='%1.1f%%')
|
28 |
+
ax.set_title('Persentase angka kematian')
|
29 |
+
st.pyplot(fig)
|
30 |
+
|
31 |
+
jender = {0: 'Perempuan', 1: 'Laki Laki'}
|
32 |
+
persentaseJender = df.replace({'sex': jender}).groupby('sex')['DEATH_EVENT'].mean()*100
|
33 |
+
st.write('Persentase kematian per jender\n',persentaseJender)
|
34 |
+
deathperjender= df.replace({'sex': jender}).groupby('sex')['DEATH_EVENT'].sum()
|
35 |
+
st.write('Total kematian per jender',deathperjender)
|
36 |
+
BP = {0: 'rendah-normal', 1: 'tinggi'}
|
37 |
+
BPx = df.replace({'high_blood_pressure': BP}).groupby('high_blood_pressure')['DEATH_EVENT'].mean()*100
|
38 |
+
st.write('Total kematian per jender',BPx)
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
if __name__== '__main__':
|
43 |
+
run()
|
image.png
ADDED
prediction.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
|
6 |
+
|
7 |
+
# Load All Files
|
8 |
+
with open('rf.pkl', 'rb') as file_1:
|
9 |
+
rf= pickle.load(file_1)
|
10 |
+
|
11 |
+
with open('GB.pkl', 'rb') as file_2:
|
12 |
+
GB=pickle.load(file_2)
|
13 |
+
|
14 |
+
with open('scaler.pkl', 'rb') as file_3:
|
15 |
+
scaler=pickle.load(file_3)
|
16 |
+
|
17 |
+
def run():
|
18 |
+
|
19 |
+
with st.form(key='form_prediksi'):
|
20 |
+
name = st.text_input('Nama', value='')
|
21 |
+
anaemia= st.radio('Apakah memiliki anaemia?', ('Ya', 'Tidak'))
|
22 |
+
if anaemia=='Ya':
|
23 |
+
anaemianum=1
|
24 |
+
else: anaemianum=0
|
25 |
+
|
26 |
+
age= st.number_input('Umur', min_value=16, max_value=80, value=50, step=1)
|
27 |
+
creatinine_phosphokinase = st.number_input('Creatinine Phosphokinase', min_value=0, max_value=2000, value=1000)
|
28 |
+
diabetes = st.radio('Apakah memiliki Diabetes?', ('Ya', 'Tidak'))
|
29 |
+
if diabetes=='Ya':
|
30 |
+
diabetesnum=1
|
31 |
+
else: diabetesnum=0
|
32 |
+
|
33 |
+
ejection_fraction = st.number_input('Ejection Fraction', min_value=0, max_value=100, value=50)
|
34 |
+
high_blood_pressure = st.radio('Apakah memiliki darah tinggi?', ('Ya', 'Tidak'))
|
35 |
+
if high_blood_pressure=='Ya':
|
36 |
+
high_blood_pressurenum=1
|
37 |
+
else: high_blood_pressurenum=0
|
38 |
+
|
39 |
+
platelets = st.number_input('Jumlah trombosit', min_value=0, max_value=300000, value=200000)
|
40 |
+
serum_creatinine = st.number_input('Serum creatinine', min_value=0, max_value=100, value=50)
|
41 |
+
serum_sodium = st.number_input('Serum sodium', min_value=0.0, max_value=2.0, value=0.4, format='%.2f', step=0.1)
|
42 |
+
sex = st.radio('Kelamin', ('Perempuan', 'Laki-Laki'))
|
43 |
+
if sex=='Laki-Laki':
|
44 |
+
sexnum=1
|
45 |
+
else: sexnum=0
|
46 |
+
|
47 |
+
smoking = st.radio('Apakah merokok?', ('Ya', 'Tidak'))
|
48 |
+
if smoking=='Ya':
|
49 |
+
smokingnum=1
|
50 |
+
else: smokingnum=0
|
51 |
+
|
52 |
+
time = st.number_input('Waktu', min_value=0, max_value=240, value=120)
|
53 |
+
|
54 |
+
submitted = st.form_submit_button('Predict')
|
55 |
+
|
56 |
+
data_inf = {
|
57 |
+
'age': age,
|
58 |
+
'anaemia': anaemianum,
|
59 |
+
'creatinine_phosphokinase':creatinine_phosphokinase,
|
60 |
+
'diabetes':diabetesnum,
|
61 |
+
'ejection_fraction':ejection_fraction,
|
62 |
+
'high_blood_pressure':high_blood_pressurenum,
|
63 |
+
'platelets': platelets,
|
64 |
+
'serum_creatinine': serum_creatinine,
|
65 |
+
'serum_sodium':serum_sodium,
|
66 |
+
'sex':sexnum,
|
67 |
+
'smoking':smokingnum,
|
68 |
+
'time':time
|
69 |
+
}
|
70 |
+
|
71 |
+
data_inf = pd.DataFrame([data_inf])
|
72 |
+
st.dataframe(data_inf)
|
73 |
+
|
74 |
+
if submitted:
|
75 |
+
|
76 |
+
data_inf_scaled=scaler.transform(data_inf)
|
77 |
+
y_pred_inf_rf = rf.predict(data_inf_scaled)
|
78 |
+
y_pred_inf_GB= GB.predict(data_inf_scaled)
|
79 |
+
st.write('# Prediksi Gradient Boosting: ', str(int(y_pred_inf_GB)))
|
80 |
+
st.write('# Prediski Randomforest: ', str(int(y_pred_inf_rf)))
|
81 |
+
|
82 |
+
if __name__== '__main__':
|
83 |
+
run()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
seaborn
|
4 |
+
matplotlib
|
5 |
+
plotly
|
6 |
+
numpy
|
7 |
+
scikit-learn==1.2.1
|
8 |
+
Pillow
|
rf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a169a590c6e166d06b38b0f1bc27d6ef67a91d0e3a5961abcfc94227a719a059
|
3 |
+
size 52783101
|
scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:85c4993c8c580ad9e0d77d4d3ac98922648dd803ec5563043eea4b6c1f68b098
|
3 |
+
size 1212
|