import streamlit as st import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import plotly.express as px from PIL import Image st.set_page_config( page_title='EDA', layout='wide', initial_sidebar_state='expanded' ) def run(): # title st.title('Predicting Patient Survival') # sub header st.subheader('Understanding Mortality Risk Factors and Predictive Modeling') # add pic image = Image.open('heart.png') st.image(image, caption='Health Parameter') # add text ''' Page ini dibuat untuk memprediksi **kematian pasien** dengan menggunakan dataset yang tersedia. Dengan melakukan explorasi, akan ditinjau beberapa insight yang dapat menjadi faktor-faktor / variabel yang membuat seorang pasien dapat diprediksi meninggal atau tidak. ''' markdown_text = ''' ## Variable Descriptions | Variable | Description | |-------------------------|-----------------------------------------------------------------------------------------------| | age | Age of the patient in years. | | anaemia | Whether the patient has anemia or not. (1=True, 0=False) | | creatinine_phosphokinase| Level of the enzyme creatinine phosphokinase in the patient's blood in units (mcg/L). | | diabetes | Whether the patient has diabetes or not. (1=True, 0=False) | | ejection_fraction | Percentage of blood volume ejected from the heart during each contraction. | | high_blood_pressure | Whether the patient has high blood pressure or not. (1=True, 0=False) | | platelets | Level of platelets in the patient's blood in units (kiloplatelets/mL). | | serum_creatinine | Level of creatinine in the patient's blood in units (mg/dL). | | serum_sodium | Level of sodium in the patient's blood in units (mEq/L). | | sex | Gender of the patient. (0=Male, 1=Female) | | smoking | Whether the patient smokes or not. (1=True, 0=False) | | time | Follow-up period in days. | | DEATH_EVENT | Indicator of whether the patient experienced a death event or not. (1=True, 0=False) | ''' st.markdown(markdown_text) st.markdown('---') st.subheader('Explorasi Data') st.markdown('---') st.write('### Tabel Data Pasien') # show dataframe data = pd.read_csv('h8dsft_P1G3_Andikaa_Atmanegara_Putra.csv') st.dataframe(data) st.markdown('---') # visual barplot st.write('### Histogram Berdasarkan User Input ') choice = st.selectbox('Pilih Columns: ', ('age', 'anaemia', 'sex', 'DEATH_EVENT', 'creatinine_phosphokinase', 'platelets')) fig = plt.figure(figsize=(15,5)) sns.histplot(data[choice], bins=30, kde=True) st.pyplot(fig) # visual 2 ## Categorical Data Plot st.write('### Categorical Data Ratio') pilihan_kategori = st.selectbox('Pick Categorical Column : ', ('anaemia', 'diabetes', 'high_blood_pressure', 'sex', 'smoking')) fig= plt.figure(figsize=(8, 6)) sns.countplot(data=data, x=pilihan_kategori, hue='DEATH_EVENT', palette=['limegreen', 'firebrick']) plt.xlabel(pilihan_kategori.capitalize()) plt.ylabel('Count') plt.title(pilihan_kategori.capitalize()+' Ratio') plt.legend(title='DEATH_EVENT') st.pyplot(fig) if __name__ == '__main__': run()