Spaces:
Sleeping
Sleeping
commit file
Browse files
app.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import eda
|
3 |
+
import prediction
|
4 |
+
|
5 |
+
navigation = st.sidebar.selectbox('Pilih Halaman : ', ('eda','Predict Death'))
|
6 |
+
|
7 |
+
if navigation == 'eda':
|
8 |
+
eda.run()
|
9 |
+
else:
|
10 |
+
prediction.run()
|
eda.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = 'Death Prediction'
|
10 |
+
)
|
11 |
+
|
12 |
+
def run():
|
13 |
+
|
14 |
+
# Membuat Title
|
15 |
+
st.title('Death Prediction Simulator')
|
16 |
+
|
17 |
+
#Sub header
|
18 |
+
st.subheader('EDA untuk analisa Dataset Death Prediction')
|
19 |
+
|
20 |
+
# Insert Gambar
|
21 |
+
#image = Image.open('')
|
22 |
+
#st.image(image, caption ='Death Prediction')
|
23 |
+
|
24 |
+
# Menambahkan Deskripsi
|
25 |
+
st.write('Page ini dibuat oleh Ferdiansyah Ersatiyo')
|
26 |
+
|
27 |
+
st.markdown('---')
|
28 |
+
|
29 |
+
|
30 |
+
#show dataframe
|
31 |
+
data = pd.read_csv('https://raw.githubusercontent.com/FerdiErs/SQL/main/h8dsft_P1G3_Ferdiansyah_Ersatiyo.csv')
|
32 |
+
st.dataframe(data)
|
33 |
+
|
34 |
+
#membuat barplot jenis kelamin
|
35 |
+
st.write('### Plot Sex')
|
36 |
+
fig = plt.figure(figsize=(10,5))
|
37 |
+
ax = sns.countplot(x='sex', data=data, palette=['b', 'r'])
|
38 |
+
ax.bar_label(ax.containers[0])
|
39 |
+
st.pyplot(fig)
|
40 |
+
|
41 |
+
#membuat histogram umur
|
42 |
+
st.write('### Histogram Umur')
|
43 |
+
fig = plt.figure(figsize=(10,5))
|
44 |
+
sns.histplot(data['age'],bins=20,kde=True)
|
45 |
+
st.pyplot(fig)
|
46 |
+
|
47 |
+
#membuat pie chart
|
48 |
+
st.write('### Pie Chart Smoking')
|
49 |
+
a= data.smoking.value_counts()
|
50 |
+
def autopct_format(values):
|
51 |
+
def my_format(pct):
|
52 |
+
total = sum(values)
|
53 |
+
val = int(round(pct*total/100.0))
|
54 |
+
return '{:.1f}%\n({v:d})'.format(pct, v=val)
|
55 |
+
return my_format
|
56 |
+
fig = plt.figure(figsize=(5,5))
|
57 |
+
a.plot.pie(subplots=True, autopct=autopct_format(a))
|
58 |
+
st.pyplot(fig)
|
59 |
+
|
60 |
+
# Membuat Histogram berdasarkan input user
|
61 |
+
st.write('### Histogram berdasarkan input user')
|
62 |
+
pilihan = st.selectbox('pilih column : ',['sex','smoking','diabetes', 'anaemia','high_blood_pressure'])
|
63 |
+
fig = plt.figure(figsize=(10,5))
|
64 |
+
ax = sns.countplot(x=data[pilihan])
|
65 |
+
ax.bar_label(ax.containers[0])
|
66 |
+
st.pyplot(fig)
|
67 |
+
|
68 |
+
if __name__== '__main__':
|
69 |
+
run()
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:31b7bda6dba0f5ad1408f5e6aa7eebbd6183fe024898a1ec164d89f946e8e739
|
3 |
+
size 203471
|
prediction.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import json
|
6 |
+
import joblib as jb
|
7 |
+
|
8 |
+
#load models
|
9 |
+
model = jb.load('model.pkl')
|
10 |
+
|
11 |
+
def run():
|
12 |
+
with st.form('key=form_prediction') :
|
13 |
+
age = st.number_input('Age', min_value=40, max_value=95, value= 60, step=1, help='Usia anda')
|
14 |
+
anaemia = st.selectbox('Anemia',(0,1), index= 1)
|
15 |
+
creatinine_phosphokinase= st.number_input('creatinine_phosphokinase', min_value=23, max_value=7861)
|
16 |
+
diabetes = st.selectbox('Diabetes',(0,1), index= 1)
|
17 |
+
ejection_fraction = st.number_input('ejection_fraction', min_value=14, max_value=80)
|
18 |
+
high_blood_pressure = st.selectbox('Tekanan Darah',(0,1), index= 1)
|
19 |
+
platelets = st.number_input('platelets', min_value=25100, max_value=850000)
|
20 |
+
serum_creatinine = st.number_input('serum creatinine',min_value=0.5,max_value=9.4)
|
21 |
+
serum_sodium = st.number_input('serum_sodium',min_value=113, max_value=148)
|
22 |
+
sex = st.selectbox('Jenis Kelamin',(0,1), index= 1)
|
23 |
+
smoking = st.selectbox('smoking',(0,1), index= 1)
|
24 |
+
time = st.slider('serum creatinine',4,135,285)
|
25 |
+
|
26 |
+
|
27 |
+
submitted = st.form_submit_button('Predict')
|
28 |
+
|
29 |
+
data_inf = {
|
30 |
+
'age': age,
|
31 |
+
'anaemia': anaemia,
|
32 |
+
'creatinine_phosphokinase':creatinine_phosphokinase,
|
33 |
+
'diabetes':diabetes,
|
34 |
+
'ejection_fraction': ejection_fraction,
|
35 |
+
'high_blood_pressure': high_blood_pressure,
|
36 |
+
'platelets' :platelets,
|
37 |
+
'serum_creatinine' :serum_creatinine,
|
38 |
+
'serum_sodium' :serum_sodium,
|
39 |
+
'sex': sex,
|
40 |
+
'smoking':smoking,
|
41 |
+
'time': time
|
42 |
+
}
|
43 |
+
|
44 |
+
data_inf = pd.DataFrame([data_inf])
|
45 |
+
st.dataframe(data_inf)
|
46 |
+
|
47 |
+
if submitted:
|
48 |
+
|
49 |
+
# Predict using bagging
|
50 |
+
y_pred_inf = model.predict(data_inf)
|
51 |
+
|
52 |
+
st.write('# Death Prediction : ', str(int(y_pred_inf)))
|
53 |
+
|
54 |
+
|
55 |
+
if __name__=='__main__':
|
56 |
+
run()
|
57 |
+
|